Key為密鑰,201701011203022017060112080720170628131328 為起始時間結束時間時間戳連起來
加密是這樣加密的嗎,得到的結果和demo給的結果不一致 請問是哪里出錯了
procedure TForm1.Button1Click(Sender: TObject);
var
B:array of byte;
P:PChar;
bs:TIdBytes;
begin
with TIdHMACSHA1.Create do
try
Key := ToBytes('Q7PIUBkWWT4i9iwSsQbRjE6eQKHFtgKM');
ParamStr := BytesToString(HashValue (ToBytes('201701011203022017060112080720170628131328')));
Memo1.Text:= Base64(ParamStr);
finally
Free;
end;
end;
function TForm1.Base64(Src: string): string;
const
DataSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
var
i, ModLen: integer;
Current: String;
Buf: array[1..3] of Byte;
NewBuf: array[1..4] of Byte;
begin
result := '';
if Src = '' then
exit;
while Length(Src) > 0 do
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] := Ord(Current[i]);
NewBuf[1] := Buf[1] shr 2;
NewBuf[2] := (Buf[1] shl 6 shr 2 or Buf[2] shr 4) and $3F;
NewBuf[3] := (Buf[2] shl 4 shr 2 or Buf[3] shr 6) and $3F;
NewBuf[4] := Buf[3] and $3F;
for i := 1 to 4 do
result := result + DataSet[NewBuf[i] + 1];
end;
if ModLen >= 1 then
result[Length(result)] := '=';
if ModLen = 1 then
result[Length(result) - 1] := '=';
end;
function IdBytesToAnsiString(ParamBytes: TIdBytes): AnsiString;
var
i: Integer;
S: AnsiString;
begin
S := '';
for i := 0 to Length(ParamBytes) - 1 do
begin
S := S + AnsiChar(ParamBytes[i]);
end;
Result := S;
end;
end.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/50792.html
標籤:VCL組件開發及應用
