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
SHA-256CFMX_COMPATMD5SHASHA-256SHA-384SHA-512UTF-8defaultCharset in the neo-runtime.xml file, which is normally UTF-8. CFMX_COMPAT algorithm.
utf-8iso-8859-1windows-1252us-asciishift_jisiso-2022-jpeuc-jpeuc-krbig5euc-cnutf-160CFMX_COMPAT default algorithm is used.
hexhex (uppercase hexadecimal), base64 or base64url (base64 with URL-safe characters and no padding). Pass it as a named argument.
hexbase64base64urladditionalIterations 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.
numIterations.
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.