I have a (unique) situation where I receive data that is a combination of encrypted (with AES-CBC) and clear-text blocks and I cannot tell which blocks are encrypted. I plan to decrypt all of the data, including the clear-text, I receive and store it locally. Before retransmitting the data, I will encrypt it again. I need the blocks that were originally in clear-text to be in their original clear-text form for the retransmission.

If I decrypt the entire original message, even the blocks that were in clear-text, and then re-encrypt it with AES-CBC and the same key used for decryption, will the originally clear-text blocks be the same after re-encryption as they were when they were received.

  • 3
    Sounds like you want to know if E(D(M,K),K) = M) where E is encryption, D is decryption, M is the message, and K Is the key. Is this correct? Please provide more background to your question, and explain your own research effort.
    – Jedi
    Commented Jul 6, 2016 at 1:04
  • Are you asking: When using AES CBC, will encrypting the same clear text with the same key multiple times produce the same encrypted text each time? Commented Jul 6, 2016 at 4:18
  • zoran2 - I rewrote your question based on comments you made to my answer. I hopefully made it more accurately represent the problem you are trying to solve. if you disagree with my edits or I somehow made it worse, please feel free to edit the question and fix it Commented Jul 6, 2016 at 14:13

1 Answer 1


Always encrypting the same text to the same value leads to data leakage, violating semantic security. To prevent this, CBC mode uses an initialization vector (IV). The IV is just a random string of bits equal to the block size of the cipher. This is XORed with the first block of clear-text to be encrypted. This makes the first encrypted block random. Each successive clear-text block is XORed with the cipher text of the previous block so that each block after the first is also random. From the Wikipedia:

enter image description here

The IV is then stored beside the encrypted text to allow decryption when the process is reversed: enter image description here

This use of the IV ensures that encrypting the same message twice will not produce the same encrypted text. CBC mode even protects against repetition in a single cipher string. So repeating bytes in the clear-text message will not encrypt to the same byte sequence.

Note that a poorly implemented CBC encryption might reuse IVs and therefore produce the same encrypted text for the same message. See this answer for more information.

  • sorry, the prob i have is: i recv data which is encrypted, but some of the data will be clear, i don't get info which block is encr/clear. When receiving: all blocks will be decrypted and stored. Later when sending back stored data just before send i decrypt. My question is: for data rcvd as clear will this always work, will i always send back what was rcvd?
    – zoran2
    Commented Jul 6, 2016 at 6:38
  • above should say: later when sending back stored data just before send i encrypt. The prob may sound weird but there is actually a reason.
    – zoran2
    Commented Jul 6, 2016 at 6:44
  • No, the data a will not be the same because the IV is random. This causes each encryption to produce different encrypted text. Commented Jul 6, 2016 at 13:56
  • ok, that't what i thought, then did some tests and it was the same. maybe i get away with it if the IV is i based on the block sequence no/position on the device (may be encr etc before used as an IV but it's not random), just a guess. If IV is random for each blk then it would have to be kept somwhere for each blk, right? i doubt that's done in this case.
    – zoran2
    Commented Jul 6, 2016 at 15:33
  • Yes, you need the IV to decrypt. If you are successfully decrypting (ie: getting the correct clear-text), then you have the correct key and IV. Re-encrypting with the same key and IV will produce the same encrypted text. So if you are keeping both the same, what you are doing might work. It's hard to be sure without knowing more details. Commented Jul 6, 2016 at 15:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .