http://forum.lazarus.freepascal.org/index.php?topic=36618.0
As for proof ...
Pascal version:
php version:
Pascal output
php output
So, once you have a solid base then you can start thinking about messing around with data that doesn't match up the requirements, therefor needs (zero-)padding, and requires fixing up the mess that base64_encode/decode functions made out of things.
And we haven't even started actually sending/receiving data over the interwebs or hashing a key... oh, you want to use ssl as well you said ?
Therefor it would be recommended to build on top of what you know is working and take small steps from there to see where things might go amiss. It might perhaps sound tedious to do but that is the only way you are able to figure out where exactly things go wrong (if they go wrong) and be able to 'fix' in case it requires fixing.
edit: php code and output matching
As for proof ...
Pascal version:
Code: Pascal [Select]
- program plip;
- {$MODE OBJFPC}{$H+}
- uses
- SysUtils
- DCPcrypt2, DCPrijndael, DCPbase64;
- function BinStr2Hex(S: AnsiString): AnsiString;
- var
- i: integer;
- begin
- Result := '';
- for i := 1 to Length(S)
- do Result := Result + LowerCase(HexStr(Byte(S[i]), 2));
- end;
- var
- Cipher : TDCP_rijndael;
- Key : AnsiString;
- IV : AnsiString;
- Data : AnsiString;
- CBC : AnsiString;
- ECB : AnsiString;
- Buffer : AnsiString;
- begin
- Data := 'Hello World_____';
- Key := '1234567890______';
- IV := '______1234567890';
- Cipher := TDCP_rijndael.Create(nil);
- Cipher.Init(Key[1], 128, @IV[1]);
- SetLength(Buffer, Length(Data));
- Cipher.EncryptECB(Data[1], Buffer[1]);
- Cipher.Free;
- ECB := Buffer;
- Cipher := TDCP_rijndael.Create(nil);
- Cipher.Init(Key[1], 128, @IV[1]);
- SetLength(Buffer, Length(Data));
- Cipher.EncryptCBC(Data[1], Buffer[1], Length(Data));
- Cipher.Free;
- CBC := Buffer;
- WriteLn('KEY : ', Key , ' (', Length(Key) , ')');
- WriteLn('IV : ', IV , ' (', Length(IV) , ')');
- WriteLn('DATA : ', Data , ' (', Length(Data), ')');
- WriteLn;
- WriteLn('ECB : ', BinStr2Hex(ECB) , ' (', Length(ECB) , ')');
- WriteLn('CBC : ', BinStr2Hex(CBC) , ' (', Length(CBC) , ')');
- WriteLn;
- ECB := Base64EncodeStr(ECB);
- WriteLn('ECB_BASE64 : ', ECB , ' (', Length(ECB) , ')');
- CBC := Base64EncodeStr(CBC);
- WriteLn('CBC_BASE64 : ', CBC , ' (', Length(CBC) , ')');
- end.
php version:
Code: PHP [Select]
- <?php
- $DATA = "Hello World_____";
- $KEY = "1234567890______";
- $IV = "______1234567890";
- echo "\n";
- echo "\n";
- ?>
Pascal output
Code: [Select]
KEY : 1234567890______ (16)
IV : ______1234567890 (16)
DATA : Hello World_____ (16)
ECB : aeb97e57a968e70c22bdfc335591b9c6 (16)
CBC : 8d0d7e91e4d0cdad7a77727c96a124f5 (16)
ECB_BASE64 : rrl+V6lo5wwivfwzVZG5xg== (24)
CBC_BASE64 : jQ1+keTQza16d3J8lqEk9Q== (24)
php output
Code: [Select]
KEY : 1234567890______ (16)
IV : ______1234567890 (16)
DATA : Hello World_____ (16)
ECB : aeb97e57a968e70c22bdfc335591b9c6 (16)
CBC : 8d0d7e91e4d0cdad7a77727c96a124f5 (16)
ECB_BASE64 : rrl+V6lo5wwivfwzVZG5xg== (24)
CBC_BASE64 : jQ1+keTQza16d3J8lqEk9Q== (24)
So, once you have a solid base then you can start thinking about messing around with data that doesn't match up the requirements, therefor needs (zero-)padding, and requires fixing up the mess that base64_encode/decode functions made out of things.
And we haven't even started actually sending/receiving data over the interwebs or hashing a key... oh, you want to use ssl as well you said ?
Therefor it would be recommended to build on top of what you know is working and take small steps from there to see where things might go amiss. It might perhaps sound tedious to do but that is the only way you are able to figure out where exactly things go wrong (if they go wrong) and be able to 'fix' in case it requires fixing.
edit: php code and output matching