procedure SHA1HmacInit(var Ctx: TSHA1Context; Key: PAnsiChar; KeyLength: Integer);
var
I: Integer;
Sum: TSHA1Digest;
begin
if KeyLength > 64 then
begin
Sum := SHA1Buffer(Key, KeyLength);
KeyLength := 32;
Key := @(Sum[0]);
end;
// FillChar(Ctx.Ipad, $36, 64);
// FillChar(Ctx.Opad, $5C, 64);
//全部HmacInit 相关的FillChar 都写反了.............................. x5你自己修改一下就行了. 这么大的bug怎么没人提?难道没人用?
FillChar(Ctx.Ipad, 64, $36);
FillChar(Ctx.Opad, 64, $5C);
for I := 0 to KeyLength - 1 do
begin
Ctx.Ipad[I] := Byte(Ctx.Ipad[I] xor Byte(Key[I]));
Ctx.Opad[I] := Byte(Ctx.Opad[I] xor Byte(Key[I]));
end;
SHA1Init(Ctx);
SHA1Update(Ctx, @(Ctx.Ipad[0]), 64);
end;
[ 本帖最后由 freecat 于 2017-9-30 14:49 编辑 ]
|