Skip to content
FutureBlitz

    Install

    Import std.crypto.derive

    Hmac

    std.crypto.derive

    struct

    Public Struct Hmac

    HMAC (RFC 2104) of data with key, of any length: a MAC as long as its hash, which only who has the key can make. Check one with ConstantTimeEquals.

    Examples

    Local message = "The quick brown fox jumps over the lazy dog"
    Local mac = Hmac.Sha256("key".Bytes, message)
    Expect(Hex.Encode(mac) == "f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8")
    // A MAC that came with a message is checked without telling where they differ.
    Expect(ConstantTimeEquals(mac, Hmac.Sha256("key".Bytes, message)))

    std/crypto/derive.fb, line 35

    • Public Static Method Sha1(key: UInt8[], data: UInt8[]): UInt8[] static method #

      HMAC-SHA1's 20 bytes, for the formats that ask for it.

    • Public Static Method Sha1(key: UInt8[], text: String): UInt8[] static method #

      HMAC-SHA1 of text's UTF-8 bytes with key.

    • Public Static Method Sha256(key: UInt8[], data: UInt8[]): UInt8[] static method #

      HMAC-SHA256's 32 bytes.

    • Public Static Method Sha256(key: UInt8[], text: String): UInt8[] static method #

      HMAC-SHA256 of text's UTF-8 bytes with key.

    • Public Static Method Sha512(key: UInt8[], data: UInt8[]): UInt8[] static method #

      HMAC-SHA512's 64 bytes.

    • Public Static Method Sha512(key: UInt8[], text: String): UInt8[] static method #

      HMAC-SHA512 of text's UTF-8 bytes with key.

    Report an issue with this page or with FutureBlitz on GitHub.