Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does an initialization vector have to be saved for decryption? [closed]

Tags:

c#

encryption

aes

I'm working on text encryption using AES. I'm saving the key and encrypted text in files, but what should i do with IV?

like image 964
user2183935 Avatar asked Sep 20 '25 14:09

user2183935


1 Answers

The IV is usually stored with the ciphertext. Prefixing the IV is commonplace as you need the IV at the start when performing decryption. As the IV is usually one block in size, you do not have to store the size of the IV if you know the block cipher used. Beware that AES-GCM, a popular authenticated mode of encryption, is most effective with a 12 byte IV.

Note that the IV is binary and often consist of randomized bytes. Neither the IV nor the ciphertext are likely to consist of valid characters. You need a encoding format such as base 64 or - less commonly - hexadecimals if you need to store the IV and ciphertext as text.

like image 118
Maarten Bodewes Avatar answered Sep 22 '25 06:09

Maarten Bodewes