View source code
Display the source code in std/digest/hmac.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

std.digest.hmac.HMAC/hmac - multiple declarations

Struct HMAC

Overload of HMAC to be used if H doesn't provide information about its block size.

struct HMAC(H, ulong hashBlockSize)
  
if (hashBlockSize % 8 == 0);

Constructors

NameDescription
this (secret) Constructs the HMAC digest using the specified secret.

Methods

NameDescription
finish () Resets the digest and returns the finished hash.
put () Feeds a piece of data into the hash computation. This method allows the type to be used as an std.range.OutputRange.
start () Reinitializes the digest, making it ready for reuse.

Example

import std.digest.sha : SHA1;
import std.string : representation;
string data1 = "Hello, world", data2 = "Hola mundo";
auto hmac = HMAC!SHA1("My s3cR3T keY".representation);
auto digest = hmac.put(data1.representation)
                  .put(data2.representation)
                  .finish();
static immutable expected = [
    197, 57, 52, 3, 13, 194, 13,
    36, 117, 228, 8, 11, 111, 51,
    165, 3, 123, 31, 251, 113];
writeln(digest); // expected

Alias/Template hmac

Overload of HMAC to be used if H doesn't provide information about its block size.

alias hmac(H) = hmac!(H,H.blockSize);
template hmac(H, ulong blockSize) ;

Alias hmac

Template hmac

Contained Functions

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

Example

import std.digest.sha : SHA1;
import std.string : representation;
string data1 = "Hello, world", data2 = "Hola mundo";
auto hmac = HMAC!SHA1("My s3cR3T keY".representation);
auto digest = hmac.put(data1.representation)
                  .put(data2.representation)
                  .finish();
static immutable expected = [
    197, 57, 52, 3, 13, 194, 13,
    36, 117, 228, 8, 11, 111, 51,
    165, 3, 123, 31, 251, 113];
writeln(digest); // expected

Authors

License

Boost License 1.0.