delphiencryptiondelphi-xe2lockbox-3

How to always get an identical result with identical settings when encrypting a string?


In Delphi XE2, with Turbopower Lockbox-3, I use the following code to encrypt a string:

Codec1.EncryptString('AText', Encrypted);

Cipher is [AES-192], ChainMode is PCBC.

However, this produces a different result each time I encrypt the same string using the same settings.
How can I always get the identical result string with the identical settings? (Password, Cipher, ChainMode, etc.).


Solution

  • With CBC mode, you are supposed to get a different ciphertext every time the encryption function is called, even with the same plaintext. This property provides protection against certain types of attacks, and is one of the reasons why CBC is more secure than ECB.

    If you still want to do it (and you should only do it if you really know what you are doing), you should use the same initialization vector (IV) every time. But as said, this can compromise the security of the system.

    I'm not familiar with your platform so I don't know how to do this in your case.