You are absolutely right that using random IV during encryption and
then another random IV during decryption will lead to garbage. What
you have to do is to send your random IV along with encrypted text.
Usually you put IV at the beginning. For example:
IV = 60ca
cipher = f576ab
you send
60caf576ab
For the decryption, you extract IV 60ca and use symetric key to
decrypt the rest of the string, in this case f576ab.
Why is it better to use random IV? Aren't we exposing it to potential
attacker if we send it along with the cipher text?
The answer is no. You could of course use static IV and make it secret
just like we keep the Key secret. However this would make encrypted
text weaker despite the fact that you keep both Key and IV secret.
Let's take an example:
secret Key = 123456
secret static IV = 4321
Now we encrypt some text:
Hello - gh78dj9dhjs8
How are you - vjsi574kjfjisre
Bye - mha8rjlsd8r3j
Hello - gh78dj9dhjs8
Everything looks fine, decryption works and we think we are safe. But
imagine you are a hacker. You try to do man-in-the-middle attack. You
will be listening on the line, collecting data and run analysis. After
a while you could notice that some texts is repeated. Also you have
different texts using the same Key and IV. Although it seems innocent
it can actually help in determining key. This type of encryption would
allow you to do some smart analysis and decrypt the message and
discover the key.
Let's see what it looks like when using randomly generated IV:
IV 7bc6
Hello - jskkj48t349h
Sending IV + text - 7bc6jskkj48t349h
IV 93d5
Hello - 834tns8of4af
Sending IV + text - 93d5834tns8of4af
IV 8fa9
How are you - kbmcj8234jdd
Sending IV + text - 8fa9kbmcj8234jdd
In this case it is true that attacker knows IV, it is the first 4
characters in the message, however it is not very useful, because in
first 2 messages the cipher is completely different despite the fact
that we are sending the same text. In case of let's say 16 byte IV, it
could take a long time before the same IV is generated and attacker
would need to listen much longer and collect much larger amounts of
data. Even if there is IV repeated after a while, 2 or 3 instances are
not enough to make deciphering the text and finding Key much easier.
To decipher the text it's probably just as hard as trying all
combinations of the key.
In case of static IV each message you send is useful for analysis as
IV is always the same.
Of course you could use static IV and keep it secret along with Key
where you don't have to encrypt to many messages. If you encrypt just
one text and you don't need to update it too often, attacker is left
with trying all combinations of the key. For network communication it
may be better to use randomly generated IV.
All depends on your application.
I hope this info will help you.
On Feb 25, 2:00 am, Robert Bielik <
robert.bie...@modularstreams.com>
wrote: