crypto.hmac
Fields
| Name | Type | Description |
|---|---|---|
md5 | | Computes a hmac using the MD5 hashing. |
sha1 | | Computes a hmac using the SHA-1 hashing. |
sha256 | | Computes a hmac using the SHA-256 hashing. |
sha384 | | Computes a hmac using the SHA-384 hashing. |
sha512 | | Computes a hmac using the SHA-512 hashing. |
Functions
crypto.hmac.digest | Computes hmac of the message using the given hash function. |
crypto.hmac.digestWithPads | Computes hmac of the message using precomputed pads from hmac.pads. |
crypto.hmac.normalizeKey | Normalizes the key to the block size of the hash function. |
crypto.hmac.pads | Computes the outer and inner pads of the key, key ⊕ opad and key ⊕ ipad. |
crypto.hmac.preset | Returns a function that computes hmac using the given hash class. |
#crypto.hmac.digest
function crypto.hmac.digest(message: string, key: string, digest_fn: fun( data: string, as_hex: boolean? ): string, block_size: integer, as_hex?: boolean): string
Computes hmac of the message using the given hash function.
Parameters
| Name | Type | Description |
|---|---|---|
message | string | The message to compute hmac for. |
key | string | The key to use. |
digest_fn | fun( data: string, as_hex: boolean? ): string | The hash function to use. |
block_size | integer | The block size of the hash function. |
as_hexoptional | boolean | true if the result should be a hex string, false otherwise. |
Returns
| Type | Name | Description |
|---|---|---|
string | hmac_str | The hmac string of the message. |
#crypto.hmac.digestWithPads
function crypto.hmac.digestWithPads(message: string, outer: string, inner: string, digest_fn: fun( data: string, as_hex: boolean? ): string, as_hex?: boolean): string
Computes hmac of the message using precomputed pads from hmac.pads.
Parameters
| Name | Type | Description |
|---|---|---|
message | string | The message to compute hmac for. |
outer | string | The outer pad. |
inner | string | The inner pad. |
digest_fn | fun( data: string, as_hex: boolean? ): string | The hash function to use. |
as_hexoptional | boolean | true if the result should be a hex string, false otherwise. |
Returns
| Type | Name | Description |
|---|---|---|
string | hmac_str | The hmac string of the message. |
#crypto.hmac.normalizeKey
function crypto.hmac.normalizeKey(key: string, digest_fn: fun( data: string ): string, block_size: integer): string
Normalizes the key to the block size of the hash function.
Keys longer than block_size are hashed first, shorter keys are padded with zero bytes.
Parameters
| Name | Type | Description |
|---|---|---|
key | string | The key to normalize. |
digest_fn | fun( data: string ): string | The hash function to use. |
block_size | integer | The block size of the hash function. |
Returns
| Type | Name | Description |
|---|---|---|
string | normalized_key | The key of exactly block_size bytes. |
#crypto.hmac.pads
function crypto.hmac.pads(key: string, block_size: integer): string, string
Computes the outer and inner pads of the key, key ⊕ opad and key ⊕ ipad.
The pads can be computed once and reused with hmac.digestWithPads for many messages under the same key.
Parameters
| Name | Type | Description |
|---|---|---|
key | string | The key normalized by hmac.normalizeKey, must be exactly block_size bytes. |
block_size | integer | The block size of the hash function. |
Returns
| Type | Name | Description |
|---|---|---|
string | outer | The outer pad. |
string | inner | The inner pad. |
#crypto.hmac.preset
function crypto.hmac.preset(hash: crypto.HashClass): fun( message: string, key: string, as_hex: boolean? ): string
Returns a function that computes hmac using the given hash class.
Parameters
| Name | Type | Description |
|---|---|---|
hash | crypto.HashClass | The hash class to use, e.g. crypto.SHA256. |
Returns
| Type | Name | Description |
|---|---|---|
fun( message: string, key: string, as_hex: boolean? ): string |