# Can I derive IV, if I know Encrypted Txt, Key and Encryption Method?

I want to know is there any way to derive the initialization vector, if I know all the other details.

Input: Hello

Key: 123

Output: xORGCDL88sa8cUrK8JNSCQ==

Now, how to find IV?

• Does the padding oracle attack is possible? If not, no! CBC mode is CPA secure. – kelalaka Oct 21 '20 at 9:27
• @kelalaka: CBC mode is not CPA secure if the adversary knows the key – poncho Oct 21 '20 at 13:07
• @poncho uh, The key is known. Forget security. The question is much easier than. use the libraries.. – kelalaka Oct 21 '20 at 13:09

I want to know is there any way to derive the initialization vector, if I know all the other details.

Well, the first block (16 bytes for AES) of CBC mode encryption is defined as:

$$C_0 = E_k( IV \oplus P_0 )$$

where $$P_0$$ is the first block of the padded plaintext, and $$C_0$$ is the first block of the ciphertext.

If you know $$C_0, P_0, k$$, then you can rearrange this into:

$$IV = P_0 \oplus D_k( C_0 )$$

where $$D_k$$ is the AES transform in decryption mode, based on key $$k$$.

This allows you to rederive the IV directly.

• Nitpick, there should be one block with hello. – kelalaka Oct 21 '20 at 13:49
• @kelalaka: that's why I said that $P_0$ is the first block of the padded plaintext; that is, the hello after padding is added – poncho Oct 21 '20 at 13:50