【问题标题】:I need to store passwords in config encrypted as password [duplicate]我需要将密码存储在加密为密码的配置中[重复]
【发布时间】:2021-08-09 03:05:45
【问题描述】:

我正在使用 Python 3 我有一个 Auth_INI ConfigParser 文件,其中用户名映射到密码。 我需要加密密码用密码所以只有密码才能解密它。

> Auth_INI = ConfigParser()
> password = 'password'
> password_encrypted = encrypt(password,'password') 
> Auth_INI['username'] = password_encrypted

它所需要的只是某种困难的散列/非散列编码。我不需要任何东西 太花哨了。没有钥匙圈,只有纯文本编码/未编码。

使用这种加密方案,我可以通过decrypt(password,'guessword') != 'guessword' 轻松验证一个人,除此之外没有理由做任何事情。

有人能推荐一个像这样工作的加密/编码库吗?

现在我只是使用 urlsafe_b64encode('password') 并且没有密码来解码密码,所以基本上没有密码加密。请帮忙...

【问题讨论】:

  • 用密码加密密码就像狗在追自己的尾巴。

标签: python encryption encode password-encryption encryption-symmetric


【解决方案1】:

来自PyNaCl 文档,这是一个快速而肮脏的示例:

import nacl.pwhash

# Password used to hash itself
orig_password = b'my password'

# Hashing the password
hashed_data = nacl.pwhash.str(orig_password)

# The result will be True on password match.
res = nacl.pwhash.verify(hashed_data, orig_password)
print(res)

# On mismatch an exception will be raised
wrong_password = b'My password'
res2 = nacl.pwhash.verify(hashed_data, wrong_password)

【讨论】:

猜你喜欢
  • 2011-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-04
  • 2011-04-18
相关资源
最近更新 更多