SHA or MD5 Digests in ColdFusion
If you need to create a message digest, you can use Java's MessageDigest class. Here's an example:
<cfset digest = CreateObject("java", "java.security.MessageDigest")> <cfset digest = digest.getInstance("SHA")> <cfset result = digest.digest(str.getBytes())> <cfset resultStr = ToBase64(result)> <cfoutput>#resultStr#</cfoutput>
There are several different digest algorithms that you can use: MD2, MD5, SHA-1, SHA-256, SHA-384, and SHA-512. To use a different algorithm, put it in the getInstance() method on the second line.
Note that the Hash function in ColdFusion can be used to create a MD5 digest of a string, it returns the result as a 32 byte hex string. The example above returns the string using Base64 encoding. You can also use this method for checking or generating MD5's on files with ColdFusion.
- What is the difference between ASCII Chr(10) and Chr(13)
- Fixinator and Foundeo Security Bundle
- Running CFML on AWS Lambda with FuseLess Slides
- Updating Java on ColdFusion or Lucee
- ColdFusion returning empty response with server-error: true
- Careful applying CF11u16, CF2016u8, CF2018u2
- Sessions don't work in Chrome but do in IE
- csrfVerifyToken does not invalidate the token