Advertisement
Guest User

Untitled

a guest
Sep 26th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.25 KB | Software | 0 0
  1. procedure TForm371.Button1Click(Sender: TObject);
  2. var
  3.   KeyArray: TBytes;
  4.   iv: TBytes;
  5.   mmIV: TAESBlock;
  6.   clearText: TBytes;
  7.   aad:  TBytes;
  8.   ciphertext: TBytes;
  9. begin
  10.  KeyArray := [$11, $11, $11, $11, $11, $11, $11, $11, $11, $11, $11, $11, $11, $11, $11, $11];
  11.  
  12.  iv := [$4D, $45, $54, $00, $00, $00, $00, $01, $00, $00, $00, $00];
  13.  FillChar(mmIv, 16, 0);
  14.  System.Move(iv[0], mmIv, System.Length(iv) );
  15.  
  16.  cleartext := [$0f, $c0, $00, $00, $01, $0c, $07, $e6, $09, $1a, $01, $03, $27, $2e, $5a, $ff, $88, $80, $02, $02, $09, $06, $00, $01, $19, $09, $00, $ff, $01, $01, $02, $06, $09, $0c, $07, $e6, $09, $1a, $01, $03, $23, $00, $00, $ff, $88, $80, $11, $5a, $17, $49, $cb, $25, $1d, $17, $49, $cb, $25, $1d, $17, $49, $cb, $25, $1d, $17, $49, $cb, $25, $1d];
  17.  aad := [$30, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33];
  18.  
  19.  setlength(ciphertext, length(cleartext));
  20.  
  21.  var mAES := TAESGCM.Create(KeyArray);
  22.  mAES.IV := mmIv;
  23.  
  24.  mAES.Encrypt(nil, nil, 0);
  25.  // Comment / Uncomment for AAD
  26.  // mAES.AesGcmAad(@aad[0], System.Length(aad));
  27.  
  28.  var rawciphertext := mAES.EncryptPkcs7(Convert(cleartext));
  29.  Move(rawciphertext[1], ciphertext[0], length(rawciphertext));
  30.  
  31.  var checktag : TAESBlock;
  32.  mAES.AesGcmFinal(checktag);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement