Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Key verification in AES

Tags:

encryption

aes

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 can I verify the key entered by the user?

like image 276
Nilesh Kumar Avatar asked May 24 '18 10:05

Nilesh Kumar


People also ask

How do I verify my AES key?

Use an HMAC. The basic premise is that you run the plaintext through an HMAC, add the result to the plaintext and then encrypt. Then do the opposite when decrypting. If the plaintext and HMAC result match, then you know you've got the correct key.

What is key in AES?

AES uses symmetric key encryption, which involves the use of only one secret key to cipher and decipher information. The Advanced Encryption Standard (AES) is the first and only publicly accessible cipher approved by the US National Security Agency (NSA) for protecting top secret information.

What is key and IV in AES?

AES algorithm requires two different parameters for encryption, a key and an initialization vector (IV). I see three choices for creating the key file: Embed hard-coded IV within the application and save the key in the key file. Embed hard-coded key within the application and save the IV in the key file.

How long is an AES key acceptable security?

Advanced Encryption Standard (AES) keys are symmetric keys that can be three different key lengths (128, 192, or 256 bits). AES is the encryption standard that is recognized and recommended by the US government. The 256-bit keys are the longest allowed by AES.


1 Answers

Use an HMAC. The basic premise is that you run the plaintext through an HMAC, add the result to the plaintext and then encrypt. Then do the opposite when decrypting. If the plaintext and HMAC result match, then you know you've got the correct key.

OR, if you want to know prior to decryption, use the key material provided by the user to derive two further keys (using, say PBKDF2). Use one for encryption and another for an HMAC. In this case, encrypt first and then apply the HMAC using the second key. This way you can compute the HMAC and check if it matches before you decrypt.

like image 177
Luke Joshua Park Avatar answered Jan 04 '23 00:01

Luke Joshua Park