Key verification in AES

后端 未结 3 1913
萌比男神i
萌比男神i 2021-01-13 03:29

If the user enters a wrong key for AES decryption, some garbage data is generated. I want to verify the given decryption key and throw an error if the key is incorrect. How

3条回答
  •  春和景丽
    2021-01-13 03:42

    Simplest approach is to add a magic number to the plaintext file data in a predictable location before encrypting; when decrypting, if the magic number is wrong, you used the wrong key. Downside to this approach is that it cannot validate the integrity/authenticity of the entire message.

    To do that, use AES in an authenticated mode (e.g. AES-GCM) which gives stronger guarantees that the rest of the message was not tampered with.

提交回复
热议问题