hash40

Converts a variable-length string to a 32-byte, hexadecimal string, using the MD5 algorithm.
Note: It is not possible to convert the hash result back to the source string.

hash40(input [, algorithm] [, encoding] [, numIterations]) → returns string

This function requires Lucee.  Not supported on Adobe ColdFusion, etc.

Argument Reference

input any
Required

String for hashing

algorithm string

The algorithm to use to hash the string. Supported are the following algorithms:
- CFMX_COMPAT: generating a hash string using classic CFML algorithm.
- MD5: (default) Generates a 32-character, hexadecimal string, using the MD5 algorithm.
- SHA: Generates a 28-character string using the Secure Hash Standard SHA-1 algorithm specified by Nation Institute of Standards and Technology (NIST) FIPS-180-2.
- SHA-256: Generates a 44-character string using the SHA-256 algorithm specified by FIPS-180-2.
- SHA-384: Generates a 64-character string using the SHA-384 algorithm specified by FIPS-180-2.
- SHA-512: Generates an 88-character string using the SHA-1 algorithm specified by FIPS-180-2.
Values:
  • CFMX_COMPAT
  • MD5
  • SHA
  • SHA-1
  • SHA-256
  • SHA-384
  • SHA-512

encoding string

Encoding which will be used by the hash algorithm

numIterations numeric
Default: 1

number of iterations

Compatibility

Lucee:

DEPRECATED since version 4.5 This function only exists for backward compatibility to Lucee 4.0 or older version that has produced an incorrect result for non us-ascii characters, Only use this function for backward compatibility.

Examples
Sample code invoking the hash40 function

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

Fork me on GitHub