hmac.hmac

Computes an HMAC digest over the given range of data with the specified secret.

  1. auto hmac(const(ubyte)[] secret)
  2. DigestType!H hmac(T data, const(ubyte)[] secret)
    template hmac(H, size_t blockSize)
    @safe
    hmac
    (
    T...
    )
    (
    scope T data
    ,
    scope const(ubyte)[] secret
    )
    if (
    allSatisfy!(isDigestibleRange, typeof(data))
    )

Return Value

Type: DigestType!H

The final HMAC hash.

Examples

import std.algorithm.iteration : map;
import std.digest.sha : SHA1;
import std.string : representation;
string data = "Hello, world";
auto digest = data.representation
              .map!(a => cast(ubyte)(a+1))
              .hmac!SHA1("My s3cR3T keY".representation);
static assert(is(typeof(digest) == ubyte[20]));
static immutable expected = [
    163, 208, 118, 179, 216, 93,
    17, 10, 84, 200, 87, 104, 244,
    111, 136, 214, 167, 210, 58, 10];
assert(digest == expected);

Meta