crypto.hmac()

Type Function
Library crypto.*
Return value String
Revision Release 2024.3703
Keywords crypto, hash, hmac

Overview

Computes HMAC (Key-Hashing for Message Authentication Code) of the string and returns it.

Syntax

crypto.hmac( algorithm, data, key [, raw] )
algorithm (required)

Constant. A constant specifying the hashing algorithm (see Constants for crypto.*).

data (required)

String. The input string.

key (required)

String. String to use as the seed for the HMAC generation.

raw (optional)

Boolean. Indicates whether the output should be a direct binary equivalent of the message digest. If false (default), the result is formatted as a hexadecimal string.

Examples

local crypto = require( "crypto" )
local hash = crypto.hmac( crypto.md5, "test", "key" )
print( hash )   --> 1d4a2743c056e467ff3f09c9af31de7e