Given this code in Delphi using DCrypt:
Uses DCPcrypt2, DCPblockciphers, DCPrijndael, DCPbase64;
procedure TForm1.Button1Click(Sender: TObject);
var Cipher : TDCP_rijndael;
ss, k, Data, Key, IV : Ansistring;
const
KeySize = 32; // 32 bytes = 256 bits
BlockSize = 16; // 16 bytes = 128 bits // IV
begin
key := '12345678901234567890123456789012';
iv := '1234567890123456';
Data := 'thisis128bitstxt';
Cipher := TDCP_rijndael.Create(nil);
Cipher.Init(Key[1],128,@IV[1]);
Cipher.EncryptCBC(Data[1],Data[1],Length(Data));
Cipher.Free;
Data := DCPBase64.Base64EncodeStr(Data);
Memo1.Lines.Add(Data);
end;
I get the following: Eq7iMlVKysMMXdhR0rtrwA==
Trying the same in PHP with OpenSSL:
<?
$s = "thisis128bitstxt";
$s = openssl_encrypt($s, "AES-128-CBC", "12345678901234567890123456789012", 0, "1234567890123456");
echo $s . "</br>";
?>
returns: Eq7iMlVKysMMXdhR0rtrwEbhkypNJyuwGafLILvwpbY=
What's wrong?
If I try to decrypt the delphi output I get an empty string:
$s = "Eq7iMlVKysMMXdhR0rtrwA==";
$s = openssl_decrypt($s, "AES-128-CBC", "12345678901234567890123456789012", 0, "1234567890123456");
echo $s . "</br>";