繁体   English   中英

我可以使用 AES IV 或随机数作为密码盐吗?

[英]Can I use the AES I.V. or nonce as a Password Salt?

我正在尝试制作一个 Python 程序,该程序将获取文件密钥,然后对文件进行加密。 我已经知道 AES-GCM 和 AES-CFB 模式分别使用 nonce 和 IV。 我目前将 IV/nonce 存储在加密文件本身中。 我正在思考这个想法是否可以使用 AES-CFB/AES-GCM 的 IV/nonce 作为我的密码散列盐?

早些时候我对提供的密钥进行了哈希处理,但是当我了解 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 已经存在的原因。 使用它们两次可能会对加密产生灾难性的影响。 根据定义,随机数是只使用一次的数字。

我意识到除了创建两个不同的随机字节之外没有更明智的方法,一个用于密码派生盐,另一个用于分组密码的随机数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM