tags:

views:

79

answers:

1

I'm writing small program to encrypt/decrypt files using AES. I'm using Cryptopp library.

I need help to understand some things.

When I'm encrypting file I should write IV at the beginning of file to decrypt it later?

I wan't to check password given do decrypt file was correct. Should I:

  • put some string at beginning of file (ex. TRUE) before it's encrypted. After decryption check it.

  • Check MD5 of file before encryption. Put it at beginning of encrypted file. Read MD5 before decryption, decrypt file, check MD5 of decrypted file and compare them.

A: 

Writing the IV at the beginning of the file is fine. Appending to the end is another option.

Do not put a static string into the plaintext: ENIGMA transcripts were more easily broken for very similar reasons, and the zip format makes brute-forcing passwords very easy for this identical mistake.

The md5 approach sounds tolerable; but hmac-sha256 would provide significantly stronger integrity claims. (I think you could even re-use the AES key or the IV for hmac-sha256, but I'm not positive of its safety.)

sarnold