delphi AES CBC 解密

使用CNPACK 的单元来实现AES CBC 解密

CBC PKCS7 解密要注意的点是,如果解密内容不够16位整除要补#0

var
 inbase64, outbase64: string;
 i:integer;
 Ret:string;
 TmpAesIv: TAESBuffer;
  IvStr: AnsiString;
  key,AesCode,data2: string;
begin
 inbase64 := GetAesCode;
//一般都是base64后的密文,先解码
 Base64Decode(inbase64, outbase64);
//判断是否足够16位整除
 i := Length(outbase64) mod SizeOf(TAESBuffer);
//不够补#0
 if i > 0 then
   outbase64 := outbase64+stringofchar(#0,SizeOf(TAESBuffer)-i);
//转16进制
 mmo1.Text := StringToHex(outbase64);

 IvStr := 'XX';
  Key := 'xxx';
  CopyMemory(@TmpAesIv, @IvStr[1], SizeOf(TmpAesIv));

Ret :=  AESDecryptCbcStrFromHex(AesCode, Key, TmpAesIv, kbt128);
     if Ret <> '' then
       Ret := UTF8Decode(StrRemovePKCS7Padding(Ret));
end;

 

posted @ 2023-10-04 00:21  Tag  阅读(234)  评论(0编辑  收藏  举报