我可以使用 AES I.V。或随机数作为密码盐?

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

我正在尝试制作一个 Python 程序,它将使用 filekey 然后它会加密文件。 我已经知道 AES-GCM 和 AES-CFB 模式分别使用随机数和 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 和随机数已经存在的原因。使用它们两次可能会对加密产生灾难性的影响。根据定义,随机数是一个只使用一次的数字。

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