[Crypto]HmacabstractKeyed message authentication (HMAC) over the SHA family. Message and key are each a String (UTF-8) or Bytes; the MAC comes back as Bytes. To CHECK a received MAC use verifySha256:message:key: — it compares in constant time, where == on the recomputed Bytes would leak timing.
([Crypto]Hmac.sha256:'msg' key:'secret').count "* -> 32
The HMAC-SHA-1 of a message under a key (20 bytes) — legacy interop (TOTP and friends), not new designs.
([Crypto]Hmac.sha1:'msg' key:'secret').count "* -> 20
The HMAC-SHA-256 of a message under a key (32 bytes).
([Crypto]Hmac.sha256:'msg' key:'secret').count "* -> 32
The HMAC-SHA-512 of a message under a key (64 bytes).
([Crypto]Hmac.sha512:'msg' key:'secret').count "* -> 64
Whether a received MAC is the HMAC-SHA-256 of the message under the key, compared in CONSTANT TIME — use this to check MACs, never == on the recomputed Bytes (equality bails at the first differing byte, leaking how much of a guess was right).
var mac = [Crypto]Hmac.sha256:'msg' key:'k' [Crypto]Hmac.verifySha256:mac message:'msg' key:'k' "* -> true