作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作一个Python程序,它将获取文件和 key ,然后加密文件。我已经知道 AES-GCM 和 AES-CFB 模式分别使用随机数和 IV。我目前将 IV/nonce 存储在加密文件本身中。我正在考虑是否可以使用 AES-CFB/AES-GCM 的 IV/nonce 作为我的密码哈希盐?
之前我对提供的 key 进行了哈希处理,但是当我了解 Rainbow-tables 时,我想到了使用更复杂的方法。我了解到的方法是 PBKDF2。
if filepath.endswith(EXT):
method = 'decrypt'
flag = False
with open(filepath, 'rb+') as f:
f.seek(-NONCE_SIZE,2)
iv = f.read()
os.truncate(filepath, os.path.getsize(filepath) - NONCE_SIZE)
# If the file doesn't end with the required extension,
# then identify the method as `encrypt` and do the same
# with the key provided.
else:
method = 'encrypt'
flag = True
iv = Random.new().read(NONCE_SIZE)
# Make a cipher object with the nonce and key and write
# to the file with the arguments.
# Previous approach as commented-out code line below
# key = hashlib.sha3_256(key.encode()).digest()
key = PBKDF2(key, iv, dkLen=32)
crp = getattr(AES.new(key, AES.MODE_GCM, nonce=iv), method)
我希望用作密码散列盐的 IV/nonce 能够提供所需的安全性。
最佳答案
这就是 IV 和 nonce 的用途。使用它们两次可能会对加密产生灾难性影响。根据定义,随机数是一个仅使用一次的数字。
关于python - 我可以使用 AES I.V.或随机数作为密码盐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56644870/
我是一名优秀的程序员,十分优秀!