unit StrAES; interface uses Windows,SysUtils,Classes,ElAES,math; function AESDecyptStr(strIn,AESKey: string): string; function AESEncryptStr(strIn,AESKey: string): string; implementation function AESDecyptStr(strIn,AESKey: string): string; function HexToString(S: string): string; var i: integer; begin Result := ''; // Go throught every single hexadecimal characters, and convert // them to ASCII characters... for i := 1 to Length( S ) do begin // Only process chunk of 2 digit Hexadecimal... if ((i mod 2) = 1) then Result := Result + Chr( StrToInt( '0x' + Copy( S, i, 2 ))); end; end; var Source: TStringStream; Dest: TStringStream; Start, Stop: cardinal; Size: integer; Key: TAESKey128; EncryptedText: TStrings; S: string; begin // Convert hexadecimal to a strings before decrypting... Source := TStringStream.Create( HexToString( strIn )); Dest := TStringStream.Create( '' ); try // Start decryption... Size := Source.Size; Source.ReadBuffer(Size, SizeOf(Size)); // Prepare key... FillChar(Key, SizeOf(Key), 0); Move(PChar(AESKey)^, Key, Min(SizeOf(Key), Length(AESKey))); // Decrypt now... DecryptAESStreamECB(Source, Source.Size - Source.Position, Key, Dest); // Display unencrypted text... Result := Dest.DataString; finally Source.Free; Dest.Free; end; end; function AESEncryptStr(strIn,AESKey: string): string; function StringToHex(S: string): string; var i: integer; begin Result := ''; // Go throught every single characters, and convert them // to hexadecimal... for i := 1 to Length( S ) do Result := Result + IntToHex( Ord( S[i] ), 2 ); end; var Source: TStringStream; Dest: TStringStream; Size: integer; Key: TAESKey128; begin // Encryption Source := TStringStream.Create(strIn ); Dest := TStringStream.Create( '' ); try // Save data to memory stream... Size := Source.Size; Dest.WriteBuffer( Size, SizeOf(Size) ); // Prepare key... FillChar( Key, SizeOf(Key), 0 ); Move( PChar(AESKey)^, Key, Min( SizeOf( Key ), Length( AESKey))); // Start encryption... EncryptAESStreamECB( Source, 0, Key, Dest ); // Display encrypted text using hexadecimals... Result := StringToHex( Dest.DataString ); finally Source.Free; Dest.Free; end; end; end.