在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
DELPHI HMAC256
unit HMAC;
interface
uses System.SysUtils, EncdDecd, IdHMAC, IdSSLOpenSSL, IdHash;
type THMACUtils = class public class function HMAC(aKey, aMessage: RawByteString): TBytes; class function HMAC_HexStr(aKey, aMessage: RawByteString): RawByteString; class function HMAC_Base64(aKey, aMessage: RawByteString): RawByteString; end;
implementation
class function THMACUtils.HMAC(aKey, aMessage: RawByteString): TBytes; var _HMAC: T; begin if not IdSSLOpenSSL.LoadOpenSSLLibrary then Exit; _HMAC:= T.Create; try _HMAC.Key := BytesOf(aKey); Result:= _HMAC.HashValue(BytesOf(aMessage)); finally _HMAC.Free; end; end;
class function THMACUtils.HMAC_HexStr(aKey, aMessage: RawByteString): RawByteString; var I: Byte; begin Result:= '0x'; for I in HMAC(aKey, aMessage) do Result:= Result + IntToHex(I, 2); end;
class function THMACUtils.HMAC_Base64(aKey, aMessage: RawByteString): RawByteString; var _HMAC: TBytes; begin _HMAC:= HMAC(aKey, aMessage); Result:= EncodeBase64(_HMAC, Length(_HMAC)); end;
end.
下面是调用的例子: program HMACSample; |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论