#1 mORMot 1 » Aes 256 Ecb Encytpt » 2023-08-14 14:40:17

narkotik
Replies: 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;

Editor

Board footer

Powered by FluxBB