簡體   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