2
我有DCPCrypt軟件包(最新版本),並試圖在AES2007中使用AES已知答案測試中的測試值進行AES/Rijndael CBC編碼(128位塊,256位密鑰) KAT)由NIST分發的矢量。一個樣品的測試向量:DCPCrypt/Delphi沒有正確編碼Rijndael
KEY = 0000000000000000000000000000000000000000000000000000000000000000
IV = 00000000000000000000000000000000
PLAINTEXT = 80000000000000000000000000000000
CIPHERTEXT = ddc6bf790c15760d8d9aeb6f9a75fd4e
下面返回的代碼:
Cyphertext (bytes): 58 215 142 114 108 30 192 43 126 191 233 43 35 217 236 52
Cyphertext (hex): 3AD78E726C1EC02B7EBFE92B23D9EC34
Cyphertext (base64): OteOcmwewCt+v+krI9nsNA==
這顯然是不正確的。
procedure TFrmKATVectors.TestData(Key,IV,PlainText: String);
var
InBuf,OutBuf: TestBuffer;
KeyBuf: KeyBuffer;
IVBuf: IVBuffer;
l,i: Integer;
Bytes,
SOut: String;
begin
Memo1.Lines.Add('Key: ' + Key);
Memo1.Lines.Add('IV: ' + IV);
Memo1.Lines.Add('Plaintext: ' + Plaintext);
l := Length(Key) DIV 2;
for i := 1 to l do KeyBuf[i] := HexToInt(Copy(Key,2*(i-1)+1,2));
l := Length(IV) DIV 2;
for i := 1 to l do IVBuf[i] := HexToInt(Copy(IV,2*(i-1)+1,2));
l := Length(PlainText) DIV 2;
for i := 1 to l do InBuf[i] := HexToInt(Copy(PlainText,2*(i-1)+1,2));
DCP_rijndael1.Init(KeyBuf,32,@IVBuf);
DCP_rijndael1.EncryptCBC(InBuf,OutBuf,TestBufSize);
SOut := '';
for i := 1 to Length(OutBuf) do
begin
SOut := SOut + Chr(OutBuf[i]);
Bytes := Bytes + IntToStr(OutBuf[i]) + ' ';
end;
Memo1.Lines.Add('Cyphertext (bytes): ' + Bytes);
Memo1.Lines.Add('Cyphertext (hex): ' + StringToHex(SOut));
Memo1.Lines.Add('Cyphertext (base64): ' + Base64EncodeStr(SOut));
Memo1.Lines.Add('');
end;
我打電話
TestData('0000000000000000000000000000000000000000000000000000000000000000',
'00000000000000000000000000000000', '80000000000000000000000000000000');
與
const
TestBufSize = 16;
type
TestBuffer = packed Array[1..TestBufSize] of Byte;
KeyBuffer = packed Array[1..32] of Byte;
IVBuffer = packed Array[1..16] of Byte;
鑑於我的測試數據的長度我回避任何填充的問題。 我在做什麼錯?有什麼建議麼?
(不,你不必述說的參數字符串長度 - 我做了好幾次。)
哇,謝謝Arnaud!我已經懷疑我忽視了一些小事。我用字節指定了大小;-) –