You are not logged in.
Pages: 1
Hello, I need AES 256 ecb encryption. I do encryption, but the result is different from online editors. What's the problem
function EncryptItAES(const s: string; const AKey: TBytes): string;
var
Key: TSHA256Digest;
Aes: TAESECB;
_s: RawByteString;
begin
Result := EmptyStr;
Key := SHA256Digest(Pointer(AKey), Length(AKey));
Aes := TAESECB.Create(Key, 256);
try
_s := StringToUTF8(s);
_s := Aes.EncryptPKCS7(_s, False);
_s := BinToBase64(_s);
Result := UTF8ToString(_s);
finally
Aes.Free();
end;
end;
procedure TForm2.Button2Click(Sender: TObject);
var
Enc: TEncoding;
Key : TBytes;
s : String;
begin
Enc := TEncoding.ANSI;
Key := Enc.GetBytes('Xk1891Js3TdaGNiXdFboGLOXHfLF0exu');
Memo1.Lines.Text := EncryptItAES('deneme',Key);
end;
Offline
I don't know.
Are you sure it is AES 256 ECB with PKCS7 padding on both sides?
Is the output totally diverse, or only the last bytes, or only the beginning?
ECB has no IV needed by definition (it is a weak unchained mode) so keep IVAtBeginning=false.
For information, the mORMot AES modes are all validated against reference vectors, and OpenSSL.
So the raw result should be correct.
There may be some trouble with the key computation, or string-to-bytes conversion, between both sides/languages.
And don't use ECB it is a weak and unsafe mode.
https://en.wikipedia.org/wiki/Block_cip … book_(ECB)
Online
Pages: 1