德尔福 10 aes 128 欧洲央行计算器错误



我正在使用TurboPower Lockbox 3。它没有给出正确的结果,我在哪里犯错误?

我在这个网站上做正确的计算。

自动计算器

我正在计算蟒蛇,我得到正确的结果。

正确的结果。

"E6861877DB7B021E8B755F927243ED7B">

当我将其计算为德尔菲时,有不同的结果。

function EncryptText_AES_128(input: string; password: string): ansistring;
var
Codec: TCodec;
CipherText: String;
begin
Codec := TCodec.Create(nil);
try
Codec.CryptoLibrary := TCryptographicLibrary.Create(Codec);
//
Codec.StreamCipherId := BlockCipher_ProgID;
Codec.BlockCipherId := Format(AES_ProgId, [128]);
Codec.ChainModeId := ecb_ProgId;
//
Codec.Password := Password;
Codec.EncryptString(input, CipherText,tencoding.UTF8);
//
Result := (CipherText);
finally
Codec.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
memo1.Lines.Add( EncryptText_AES_128(#$00#$01#$02#$03#$04#$05#$06#$07#$08#$09#$0a#$0b#$0c#$0d#$0e#$0f,#$78#$34#$90#$fd#$6a#$6c#$90#$f0#$72#$36#$a8#$ed#$40#$27#$94#$f8#$73#$2c#$96#$fb#$71#$1f#$a0#$f4#$6c#$34#$9a#$c4#$79#$24#$93#$e8));
end;

我哪里犯了错误?

我已经在你的老问题 Aes 128 ecb delphi 中告诉过你,#$78#$34#$90#$fd#$6a#$6c#$90#$f0#$72#$36#$a8#$ed#$40#$27#$94#$f8#$73#$2c#$96#$fb#$71#$1f#$a0#$f4#$6c#$34#$9a#$c4#$79#$24#$93#$e8不是 128 位密钥。

我可以重现输出 如果我使用AES-256-ECB,您的在线计算器带有我自己的例程。这里完整的程序和输出

uses
aes_type, aes_ECB, mem_util;
var
Context: TAESContext;
ct: array[0..50] of byte;
const
pt: array[0..15] of byte = ($00,$01,$02,$03,$04,$05,$06,$07,
$08, $09,$0a,$0b,$0c,$0d,$0e,$0f);
const
key256 : array[0..31] of byte = ($78,$34,$90,$fd,$6a,$6c,$90,$f0,
$72,$36,$a8,$ed,$40,$27,$94,$f8,
$73,$2c,$96,$fb,$71,$1f,$a0,$f4,
$6c,$34,$9a,$c4,$79,$24,$93,$e8);
begin
AES_ECB_Init_Encr(key256, 256, context);
AES_ECB_Encrypt(@pt, @ct, sizeof(pt), context);
writeln(hexstr(@ct, sizeof(pt)));
end.
D:BP_WEWORKAESBASE>C:ProgrammeBORLANDDELPHI6BinDCC32 -uC:ProgrammeBOR
LANDDELPHI6LIB;. -b -q -cc t_ecb.pas
Borland Delphi Version 14.0
Copyright (c) 1983,2002 Borland Software Corporation
6290 lines, 0.11 seconds, 13144 bytes code, 6805 bytes data.
D:BP_WEWORKAESBASE>T_ECB.EXE
e6861877db7b021e8b755f927243ed7b

如果我使用 AES-128,结果是df6dfb1fca78323413c9ec48a3162b0a.因此,如果您想获得与计算器相同的输出,请使用 AES-256。

最新更新