Delphi で String を HMAC-SHA1

Delphi で String を HMAC-SHA1 + Base64

uses へ IdCoderMIME, IdHMACSHA1 を追加して
function HMAC_SHA1_Str(S, Key: string): string;
var
    HmacSha: TIdHMACSHA1;
    Hash: TidBytes;
    Base64: TIdEncoderMIME;
begin
    HmacSha := TIdHMACSHA1.Create;
    Base64 := TIdEncoderMIME.Create;
    try
        HmacSha.Key := TIdBytes(TEncoding.UTF8.GetBytes(Key));
        Hash := HmacSha.HashValue(TIdBytes(TEncoding.UTF8.GetBytes(S)));

        Result := Base64.EncodeBytes(Hash);
    finally
        Base64.Free;
        HmacSha.Free;
    end;
end;

コメント