GLib.Hmac.new
Description: Reference for GLib.Hmac.new

### Function

# GLib Hmacnew

since: 2.30

#### Declaration [src]

    GHmac*
    g_hmac_new (
      GChecksumType digest_type,
      const guchar* key,
      gsize key_len
    )

#### Description [src]

Creates a new `GHmac`, using the digest algorithm `digest_type`. If the `digest_type` is not known, `NULL` is returned. A `GHmac` can be used to compute the HMAC of a key and an arbitrary binary blob, using different hashing algorithms.

A `GHmac` works by feeding a binary blob through `g_hmac_update()` until the data is complete; the digest can then be extracted using g_hmac_get_string(), which will return the checksum as a hexadecimal string; or g_hmac_get_digest(), which will return a array of raw bytes. Once either `g_hmac_get_string()` or `g_hmac_get_digest()` have been called on a `GHmac`, the HMAC will be closed and it won’t be possible to call `g_hmac_update()` on it anymore.

Support for digests of type `G_CHECKSUM_SHA512` has been added in GLib 2.42. Support for `G_CHECKSUM_SHA384` was added in GLib 2.52.

Available since: 2.30

#### Parameters

`digest_type`

  Type: `GChecksumType`

  The desired type of digest.

`key`

  Type: An array of `guchar`

  The key for the HMAC.

  The length of the array is specified in the `key_len` argument.
  The data is owned by the caller of the function.

`key_len`

  Type: `gsize`

  The length of the keys.

#### Return value

Type: `GHmac`

The newly created `GHmac`, or `NULL`. Use `g_hmac_unref()` to free the memory allocated by it.

The caller of the function takes ownership of the data, and is responsible for freeing it.
The return value can be `NULL`.