Search code examples
javaencryptioncryptographyinitialization-vector

Initialization Vector on Cryptography



I have a question regarding how initialization vector works on cryptography.

I have bit of knowledge about creating a IV and my question would be this,
I know about SecureRandom class so once I create a IV through this it will perfectly encrypt the data, what I don't understand is how can you get the same IV for the decryption process? (Please explain I need to know about this to create an algorithm for a assignment)


Solution

  • Usually, the IV is sent along with the ciphertext in network protocols, or stored somewhere along with the ciphertext, e.g. at the beginning of the file in a file encryption scheme. For block ciphers in CBC mode, it is very common to simply send or store the IV as first ciphertext block. The IV is not a secret, but depending on your cryptosystem, it should not be reused or be predictable.