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() and decrypt()
  • 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!


1 Answer 1


For AES-CBC, if you have the key, but not the IV, then you can still decrypt the entire message, except for the first block. See https://crypto.stackexchange.com/questions/1129/can-cbc-ciphertext-be-decrypted-if-the-key-is-known-but-the-iv-not for more information.

  • 3
    Its probably worth noting that this answer is specific to the AES-CBC encryption specified by the OP. In general, there is no guarantee that any given encryption algorithm will treat the IV in the same way.
    – Cort Ammon
    Aug 28, 2020 at 7:23
  • @CortAmmon good point. I've edited my answer to clarify this.
    – mti2935
    Aug 28, 2020 at 10:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .