hash

Converts a string into a fixed length hexadecimal string.

NOTE: The result is useful for comparison and validation, such as storing and validating a hashed password without exposing the original password.

hash(string [, algorithm [, encoding]] [, additionalIterations]) → returns string

Argument Reference

string string
Required

algorithm string
Default: SHA-256

CF 7+ 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.

NOTE: The default is SHA-256 in CF 2025+, CF 2023.0.8+ and CF 2021.0.14+. Earlier versions default to CFMX_COMPAT, which produces an MD5 hash. Lucee defaults to MD5.

NOTE: The Enterprise Edition of ColdFusion installs the RSA BSafe Crypto-J library, which provides FIPS-140 Compliant Strong Cryptography. This includes additional algorithms. You can also install additional cryptography algorithms and use those hashing algorithms.
Values:
  • CFMX_COMPAT
  • MD5
  • SHA
  • SHA-256
  • SHA-384
  • SHA-512

encoding string
Default: UTF-8

CF 7+ 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.

NOTE: The default is specified by the value of defaultCharset in the neo-runtime.xml file, which is normally UTF-8.
NOTE: This is ignored when using the CFMX_COMPAT algorithm.
Values:
  • utf-8
  • iso-8859-1
  • windows-1252
  • us-ascii
  • shift_jis
  • iso-2022-jp
  • euc-jp
  • euc-kr
  • big5
  • euc-cn
  • utf-16

additionalIterations numeric
Default: 0

CF 10+ 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.

NOTE: This parameter appears to be ignored if the CFMX_COMPAT default algorithm is used.

outputEncoding string
Default: hex

CF 2025+ The format of the returned hash: hex (uppercase hexadecimal), base64 or base64url (base64 with URL-safe characters and no padding). Pass it as a named argument.
Values:
  • hex
  • base64
  • base64url

Compatibility

ColdFusion:

Version 4.5+ CF7 added additional algorithm support, CF10 added the iterations option. CF2018 uses additionalIterations as the iterations param. The default algorithm changed from CFMX_COMPAT (MD5) to SHA-256 in CF2023.0.8+ and CF2021.0.14+. CF2025+ removed the CFMX_COMPAT algorithm and added outputEncoding, which must be passed as a named argument (the fourth positional argument is still additionalIterations). In 2025.0.14, passing outputEncoding without additionalIterations hashes one extra time, so also pass additionalIterations=0; omitting algorithm with outputEncoding throws an error.

Lucee:

The iterations value represents the total number of hashes on Lucee, in Adobe CF the value is the number of additional iterations. In Lucee5+, the iterations param is numIterations.

RustCFML:

Lucee iterations semantics differ slightly.

Links more information about hash

Examples
Sample code invoking the hash function

Returns 64 character hex result.

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

Expected Result: 3FC9B689459D738F8C88A3A48AA9E33542016B7A4052E001AAA536FCA74813CB

MD5 is not recommended for use requiring security. Without an algorithm, this returns an MD5 hash only on engines where MD5 is the default (Lucee, and ColdFusion before 2023.0.8 or 2021.0.14). Newer ColdFusion versions return a SHA-256 hash.

hash("something")

Expected Result: 437B930DB84B8079C2DD804A71936B5F

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

Fork me on GitHub