hmac

Creates a keyed-hash message authentication code (HMAC), which can be used to verify authenticity and integrity of a message by two parties that share the key.

hmac(message, key, [, algorithm] [, encoding] ) → returns String

Argument Reference for the hmac function

message

Required: Yes
The message or data to autenticate

key

Required: Yes
The secret key.

algorithm

Required: No
Default: HMACMD5
An algorithm supported by the java crypto provider, for example HMACSHA256 Values:
  • HMACMD5
  • HMACSHA1
  • HMACSHA256
  • HMACSHA384
  • HMACSHA512

encoding

Required: No
Default: utf-8
The character encoding to use when converting the message to bytes. Must be a character encoding name recognized by the Java runtime. Values:
  • utf-8
  • iso-8859-1
  • windows-1252
  • us-ascii
  • shift_jis
  • iso-2022-jp
  • euc-jp
  • euc-kr
  • big5
  • euc-cn
  • utf-16

Links more information about hmac

Examples sample code invoking the hmac function


Example HMAC Using HMACSHA256

hmac("msg", "secret", "HMACSHA256")

Expected Result: FE4F9C418F683F034F6AF90D1DD5B86AC0355DD96332C59CC74598D0736107F6


Fork me on GitHub