hash

Converts a string into a fixed length hexadecimal string.

hash(String [, algorithm] [, encoding] [, iterations]) → returns string

hash Argument Reference

String string
Required

algorithm string
Default: MD5

A supported algorithm such as MD5,SHA,SHA-256,SHA-384, or SHA-512. Of those listed SHA-512 is the strongest and generates a 128 character hex result. CF 7+
Values:
  • CFMX_COMPAT
  • MD5
  • SHA
  • SHA-256
  • SHA-384
  • SHA-512

encoding string

A string specifying the encoding to use when converting
the string to byte data used by the hash algorithm.
Must be a character encoding name recognized by the
Java runtime. CF 7+
Values:
  • utf-8
  • iso-8859-1
  • windows-1252
  • us-ascii
  • shift_jis
  • iso-2022-jp
  • euc-jp
  • euc-kr
  • big5
  • euc-cn
  • utf-16

iterations numeric
Default: 1

Iterates the number of times the hash is computed to create a more computationally intensive hash. Lucee and Adobe CF implement this differently (off by one), see compatibility notes below. CF 10+

Compatibility

ColdFusion:

CF7 added additional algorithm support, CF10 added the iterations option.

Lucee:

The iterations value represents the total number of hashes on Lucee, in Adobe CF the value is the number of additional iterations.

Examples sample code invoking the hash function


SHA-256 Hash Example

Returns 64 character hex result.

hash("something", "SHA-256", "UTF-8")

Expected Result: 3FC9B689459D738F8C88A3A48AA9E33542016B7A4052E001AAA536FCA74813CB


MD5 Hash Example

MD5 is not recommended for use requiring security.

hash("something")

Expected Result: 437B930DB84B8079C2DD804A71936B5F


Fork me on GitHub