TL;DR
If we encrypt a message with an IV, do we need to store this specific IV somewhere to ensure that we're able to decrypt the message later?
There isn't much I know about this. From my understanding, IVs are a way of creating different ciphertext each time the same message is encrypted.
The Problem
I encrypted a message with a particular random IV, and stored the encrypted message (say, a file).
Now, I tried decryption with a random IV (different from the one used for encryption), and got gibberish text, instead of the original plain text message which I expected.
But, if I decrypt with the same IV as used in encryption, I see my original plain text message.
If this is indeed the case, how is an encryption key different from an IV?
Implementation Information
I don't think the following has to do with encryption per se, but it's there in case someone needs it:
- I'm using two JavaScript functions,
encrypt()
anddecrypt()
- Calling those two with the same globally defined IV gets me the original message on decryption.
- Calling those two with different IVs inside them gets me gibberish.
- Here is the code if someone needs to have a look. -I am using AES in CBC mode
Appreciate an answer!