Class (GI Struct)

GLib-2.0GLibHmacSince 2.30

HMACs should be used when producing a cookie or hash based on data and a key. Simple mechanisms for using SHA1 and other algorithms to digest a key and data together are vulnerable to various security issues. HMAC uses algorithms like SHA1 in a secure way to produce a digest of a key and data.

Both the key and data are arbitrary byte arrays of bytes or characters.

Support for HMAC Digests has been added in GLib 2.30, and support for SHA-512 in GLib 2.42. Support for SHA-384 was added in GLib 2.52.

To create a new GLib.Hmac, use GLib.Hmac.new. To free a GLib.Hmac, use GLib.Hmac.unref.

2.30

Index

Constructors

Properties

$gtype: GType<GLib.Hmac>

Methods

  • Gets the digest from checksum as a raw binary array and places it into buffer. The size of the digest depends on the type of checksum.

    Once this function has been called, the GLib.Hmac is closed and can no longer be updated with g_checksum_update().

    Parameters

    • buffer: string | Uint8Array<ArrayBufferLike>

      output buffer

    Returns void

  • Gets the HMAC as a hexadecimal string.

    Once this function has been called the GLib.Hmac can no longer be updated with g_hmac_update().

    The hexadecimal characters will be lower case.

    Returns string

    the hexadecimal representation of the HMAC. The returned string is owned by the HMAC and should not be modified or freed.

  • Atomically decrements the reference count of hmac by one.

    If the reference count drops to 0, all keys and values will be destroyed, and all memory allocated by the hash table is released. This function is MT-safe and may be called from any thread. Frees the memory allocated for hmac.

    Returns void

  • Feeds data into an existing GLib.Hmac.

    The HMAC must still be open, that is g_hmac_get_string() or g_hmac_get_digest() must not have been called on hmac.

    Parameters

    • data: string | Uint8Array<ArrayBufferLike>

      buffer used to compute the checksum

    Returns void