3

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() 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!

roshnet
  • 131
  • 4
  • 4
    You need to use the same IV for encryption and decryption. Does this answer your question? [Why does IV not need to be secret in AES CBC encryption?](https://security.stackexchange.com/questions/122274), [When using AES and CBC, is it necessary to keep the IV secret?](https://security.stackexchange.com/questions/17044/), [How to store an AES Key? an Initialization Vector(IV)?](https://security.stackexchange.com/questions/153055/) – Steffen Ullrich Aug 24 '20 at 10:51
  • See the [block cipher mode of operation](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation). IV is used for randomizing the encryption and re-using a key for a long time. – kelalaka Aug 24 '20 at 11:15
  • 1
    @SteffenUllrich I agree, but with AES-CBC, it's possible to decrypt the entire message, except for the first block, without the IV, if you have the key. See https://crypto.stackexchange.com/questions/1129/can-cbc-ciphertext-be-decrypted-if-the-key-is-known-but-the-iv-not. – mti2935 Aug 24 '20 at 17:03

1 Answers1

2

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.

mti2935
  • 19,868
  • 2
  • 45
  • 64
  • 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 '20 at 07:23
  • @CortAmmon good point. I've edited my answer to clarify this. – mti2935 Aug 28 '20 at 10:57