Function getNewHMACKey

  • generate new HMAC key with specified HMAC algorithm

    Parameters

    • alg: string

      HMAC algorithm ("hmacSHA{1,256,384,512}")

    Returns string

    hexadecimal string of HMAC key

    Description

    This function generates a HMAC key with specified HMAC algorithm with crypto.getRandomValues not crypto.subtle.generateKey. Its byte length will be the same as generateKey as following:

    • hmacSHA1, hmacSHA256: 64 bytes
    • hmacSHA384, hmacSHA512: 128 bytes

    Example

    getNewHMACKey("hmacSHA256") -> "8ab134..." (64 bytes)
    getNewHMACKey("hmacSHA512") -> "374cdf..." (128 bytes)