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

message any

The message or data to authenticate. This can be a String or a byte array.

key any

The secret key. The key can be a String or byte array.

algorithm string
Default: HMACMD5

An algorithm supported by the java crypto provider.
  • HMACSHA256
  • HMACSHA384
  • HMACSHA512

encoding string
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.
  • 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

Sample code invoking the hmac function

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

Expected Result: FE4F9C418F683F034F6AF90D1DD5B86AC0355DD96332C59CC74598D0736107F6

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub