Home > Back-end >  On HmacSHA1 encryption, inconsistent results and want something wrong
On HmacSHA1 encryption, inconsistent results and want something wrong

Time:09-18

The Key to the Key, 201701011203022017060112080720170628131328 as the starting time to end time timestamp together
Encryption is encrypted, the result and the result of the demo to inconsistent excuse me, is something wrong

Procedure TForm1. Button1Click (Sender: TObject);
Var
B: an array of byte;
P: PChar;
Bs: TIdBytes;
The begin


With TIdHMACSHA1. Create the do
Try
Key:=ToBytes (' Q7PIUBkWWT4i9iwSsQbRjE6eQKHFtgKM ');
ParamStr: BytesToString=(HashValue (ToBytes (' 201701011203022017060112080720170628131328 ')));
Memo1. Text:=Base64 (ParamStr);
The finally
Free;
end;
end;
The function TForm1. Base64 (Src: string) : string;
Const
The DataSet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 +/=';
Var
I, ModLen: integer;
Current: String;
Buf: array [3] 1.. of Byte;
NewBuf: array [4] 1.. of Byte;

The begin
Result:=';
If Srchttps://bbs.csdn.net/topics/='then
exit;
While Length (Src) & gt; 0 do
The begin
ModLen:=Length (Src) mod 3;
FillChar (Buf, 3 # 0);
Current:=Copy (Src, 1, 3);
Src=Copy (Src, 4, Length (Src) - 3);
For I:=1 to 3 do
Buf: [I]=word (Current [I]);
NewBuf [1] :=Buf [1] SHR 2;
NewBuf [2] :=(Buf [1] SHL 2 or 6 SHR Buf [2] SHR 4) and $3 f;
NewBuf [3] :=(Buf [2] SHL SHR 2 or 4 Buf [3] SHR 6) and $3 f;
NewBuf [4] :=Buf [3] and $3 f;
For I:=1 to 4 do
Result: the result=+ DataSet [NewBuf [I] + 1];
end;
If ModLen & gt;=1 then
Result [Length (result)] :='=';
If ModLen=1 then
Result [Length (result) - 1] :='=';
end;



The function IdBytesToAnsiString (ParamBytes: TIdBytes) : AnsiString;
Var
I: Integer;
S: AnsiString.
The begin
S:=';
For I:=0 to Length (ParamBytes) - 1 do
The begin
S:=S + AnsiChar (ParamBytes [I]);
end;
Result:=S;
end;
end.
  • Related