We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Initialization Vectors

As we briefly mentioned before, an iv, or initialization vector, is a random value that is used to initialize a block cipher. It is used to ensure that the same plaintext always encrypts to a different ciphertext.

Nonce

If the iv doesn't need to be truly random, and the only requirement is that it's only used once, then it's often called a "nonce", which is just short for "a number used only once".

Whether the iv for an encryption algorithm needs to be cryptographically random, pseudorandom, or just unique will be specified in the documentation for that algorithm. It's important to read the documentation for the algorithm you're using to ensure that you're providing the correct level of security for your iv.

Assignment

Update the generateIV function. It's currently returning unique values due to a global count variable, but it's not random, which is what Passly's cipher requires.

Use the crypto/rand package's rand.Read function to generate a random iv of the specified byte length.