const
KeySize = 32; // 256 bits
BlockSize = 16; // 128 bits
Key := 'simple24characterkey1234';
IV := 'simple16byteiv12';
ToEncrypt := 'j...@test.nl';
ToEncrypt := PadWithZeros(ToEncrypt,BlockSize); // Pads a string with #0
so that it is a multiple of BlockSize
{ Bytes of padded string to encrypt: }
{ 6a 61 6e 40 74 65 73 74 2e 6e 6c 00 00 00 00 00 }
Cipher := TDCP_rijndael.Create(Self);
Cipher.Init(Key[1],8*KeySize,@IV[1]);
Cipher.EncryptCBC(ToEncrypt[1],ToEncrypt[1],Length(ToEncrypt));
Cipher.Free;
FillChar(Key[1],KeySize,0);
{ Bytes of encrypted string: }
{ 18 e6 be 0e aa 36 6f a4 b7 9d 93 c8 08 c6 0f 56 }
If I try to decrypt this with MCrypt in PHP I get gibberish.
So I tried to encrypt with MCrypt to compare the two:
$rkey = 'simple24characterkey1234';
$riv = 'simple16byteiv12';
$data = 'j...@test.nl';
$data = mcrypt_cbc(MCRYPT_RIJNDAEL_128,$rkey,$data,MCRYPT_ENCRYPT,$riv);
Now the bytes of the encrypted string are:
f8 a1 0d 75 58 2a 26 de f5 6b 84 bd 3a 45 b2 5e
So this does not exactly match ;-(
Help, what can I use that works?
Thanks
Jan
========================================================================================
http://www.jandoggen.org http://www.beautyofpeople.com
http://www.puddingclub.nl
Using StreamSec Tools 2.1 (which is equivalent to OpenStrSecII on
sourceforge.net in case you want an open source library), the following
code results yields the same output as the mcrypt PHP library:
uses
SecUtils, SsRijndael;
var
lKey: AnsiString;
lC: TCipher;
lS: AnsiString;
begin
lKey := 'simple24characterkey1234';
lS := 'j...@test.nl'#0#0#0#0#0;
UniqueString(lS);
lC := TRijndael_CBC.Create(Pointer(lKey)^,Length(lKey),0);
try
lC.IVector := 'simple16byteiv12';
lC.Encrypt(Pointer(lS)^,Length(lS));
finally
lC.Free;
end;
ShowMessage(BinToHex(Pointer(lS)^,Length(lS)));
Jan
"Henrick Hellström" <hen...@streamsec.se> schreef in bericht
news:47ff...@newsgroups.borland.com...