Cryptography guru, please help.
I found out that an encryption key with symmetric algorithms (for example, AES) must be obtained from the password through the PBKDF2 function, using a random salt in each encryption. I also found out that IV should not be hardcoded or directly connected to a password string or encryption key. Until now, I randomly generated both a key and IV, 16 bytes for my AES-256 encryption, and saved them along with the encrypted payload.
Now I think that random generation IV is redundant if I use random salt, as I can deduce both the key and the IV from the password string with this salt. Or maybe I shouldn't?
So my question in the end is this:
Is it possible to deduce the initialization vector from the password (as I do with the key), or should I generate a random IV every time, given the fact that I use a random salt in each encryption?
So, can I use the C # code below?
// Derive key and initialization vector from password: // ---> NOTE: _salt is random 16 bytes in each encryption. byte[] key, iv; using (Rfc2898DeriveBytes derivedBytes = new Rfc2898DeriveBytes(password, _salt, _iterations)) { key = derivedBytes.GetBytes(32); iv = derivedBytes.GetBytes(16); }
source share