You are not logged in.
Pages: 1
i used SynCrypto to encrypt plaintext with aes/ecb/PKCS7padding, but the encrypted text was different from the one encrypted using Wcrypt2 from http://delphi-jedi.org.
i need the encrypted text could be used by php, but i can not manage it.
here is my code:
function EncryptMsgData(MsgData, Key: string): string;
var
i:integer;
ECB:TAESECB;
iv:TAESBlock;
begin
Result:= '';
for i:=0 to 15 do
begin
if i > (length(Key) - 1) then
iv[i] := 0
else
iv[i] := byte(Key[i + 1]);
end;
try
ECB := TAESECB.Create(Key,128,iv);
result := ECB.EncryptPKCS7(MsgData);
finally
ECB.Free;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
CText.Text := strtohex(EncryptMsgData('123456','1234567890123456'));
end;
with SynCrypto:
plaintext:123456
key:1234567890123456
result:BBB958B46D43174355EBBCACDDE1A171
with wcrypt2(aes/ecb/PKCS5padding)
plaintext:123456
key:1234567890123456
result:C97554911E393C5CF451FA5B0C1F3F7B
by the way, how to create TAESECB from SynCrypto without IV, and function EncryptPKCS5 is missing.
thanks.
Last edited by profh (2013-12-14 07:55:16)
Offline
With use this unit in production with Java and C# code, and it gives the very same exact results.
So I guess the problem is not in the units themselves.
Which version of Delphi are you using?
Perhaps you are mixing Unicode and Ansi strings.
Offline
i use delphi 7, but i can not get the result: C97554911E393C5CF451FA5B0C1F3F7B.
Last edited by profh (2013-12-15 02:18:40)
Offline
This is not the same padding, so it does not give the same result.
See http://crypto.stackexchange.com/a/9044
PKCS#5 is limited to 8 bytes = 64 bit blocks, which is not correct when working with AES.
You should better switch to PKCS#7, which allows block sizes up to 256 bytes in size.
Offline
with SynCrypto:
plaintext:123456
key:1234567890123456
result:BBB958B46D43174355EBBCACDDE1A171
is the result above correct with PKCS#7?
Could you add a function as EncryptPKCS5?
i just want them to get the same result "C97554911E393C5CF451FA5B0C1F3F7B" to work together.
Last edited by profh (2013-12-15 10:59:13)
Offline
using sample SymmetricCrypto from http://www.torry.net/vcl/security/stron … boxvcl.zip, i got the same result "C97554911E393C5CF451FA5B0C1F3F7B", but i prefer to use syncrypto.
thanks.
Last edited by profh (2013-12-15 14:02:32)
Offline
Pages: 1