Delphi で String を HMAC-SHA1

Delphi で String を HMAC-SHA1 + Base64

uses へ IdCoderMIME, IdHMACSHA1 を追加して
  1. function HMAC_SHA1_Str(S, Key: string): string;  
  2. var  
  3.     HmacSha: TIdHMACSHA1;  
  4.     Hash: TidBytes;  
  5.     Base64: TIdEncoderMIME;  
  6. begin  
  7.     HmacSha := TIdHMACSHA1.Create;  
  8.     Base64 := TIdEncoderMIME.Create;  
  9.     try  
  10.         HmacSha.Key := TIdBytes(TEncoding.UTF8.GetBytes(Key));  
  11.         Hash := HmacSha.HashValue(TIdBytes(TEncoding.UTF8.GetBytes(S)));  
  12.   
  13.         Result := Base64.EncodeBytes(Hash);  
  14.     finally  
  15.         Base64.Free;  
  16.         HmacSha.Free;  
  17.     end;  
  18. end;  

コメント