Hi guys, I'm writing a program that needs some components that conflict but only on windows (on mac they work). I isolated the problem in an example I am attaching. If you run the program you will see that the decryption is not successful, it returns a different result from the input. While if from project1.lpr try to comment on the unit uinit everything works. I think there is something that conflicts with the DecodeBase64 function. But I don't understand how to solve. Who helps me? thanks a lot
Hi, first of all I must say you are doing quite a number of unsafe and wrong things with respect to Cryptography in your code.
1. As Thaddy said, Cryptographic operations is done on
Byte Arrays not
Strings. performing them on strings will lead to loss of information in the long run.
2. Never use a password as your AES Key directly, rather use a Key stretching algorithm like PBKDF2 or Argon2 to generate a suitable key to use for your operation.
3. Your IV is meant to be a random sequence of bytes that (all things being equal ) and should not be used to encrypt more than one message. where things are done properly, an IV is regenerated for every new encryption operation that is to be done and prefixed to the encrypted message so it can be extracted when needed.
4. AES uses an IV of 16 bytes not 32.