There are a few variations of this question around but i haven't been able to pin the problem down. Trying to encrypt/unencrypt in PHP and Delphi I assume I have missed some setting in Delphi and its to do with UTF-8
using http://aesencryption.net/ as a PHP Example the result we are trying to get. Image Blow
Password = 123
Key = Test
128 bit
Encrypts to uuIikEZSC9Sa1HAt/XKfGQ==
I want to be able to unencrypt this in Delphi
I'm using Delphi XE5
with https://github.com/SeanBDurkin/tplockbox
I can get encrypt/DeCrypt working inside Delphi but the PHP encrypted version string is different
Delphi encrypts 123 to vpdeLlfnxTGrSsa2TpbFvg==
Here is a quick example of the Delphi Encrypt
function TForm3.EncryptV2(plainText: UTF8String): String;
var CipherText : string;
FLibrary: TCryptographicLibrary;
FCodec: TCodec;
begin
mmo1.Lines.Add('plaintext = ' + plainText);
FLibrary := TCryptographicLibrary.Create(Self);
try
FCodec := TCodec.Create(Self);
try
FCodec.CryptoLibrary := FLibrary;
FCodec.StreamCipherId := BlockCipher_ProgId;
FCodec.BlockCipherId := Format(AES_ProgId, [256]);
FCodec.ChainModeId := ECB_ProgId; ;
FCodec.UTF8Password := 'test';
FCodec.EncryptString( plainText, CipherText, Tencoding.UTF8 );
FCodec.Burn;
result := CipherText;
finally
FCodec.Free;
end;
finally
FLibrary.Free;
end;
end;
Decrypt
function TForm3.DecryptV2(encryptedText: UTF8String): String;
var plainText : string;
FLibrary: TCryptographicLibrary;
FCodec: TCodec;
begin
FLibrary := TCryptographicLibrary.Create(Self);
try
FCodec := TCodec.Create(Self);
try
FCodec.CryptoLibrary := FLibrary;
FCodec.StreamCipherId := BlockCipher_ProgId;
FCodec.BlockCipherId := Format(AES_ProgId, [256]);
FCodec.ChainModeId := ECB_ProgId; ;
FCodec.UTF8Password := 'test';
mmo1.Lines.Add('Encrypted Text = ' + encryptedText);
FCodec.DecryptString( plainText, encryptedText,Tencoding.UTF8 );
mmo1.Lines.Add('DeCrypted Text = ' + plainText);
result := plainText;
finally
FCodec.Free;
end;
finally
FLibrary.Free;
end;
end;
Anyone have any suggestions?