pf » SHA or MD5 Digests in ColdFusion
January 25, 2005
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.
Trackback Address: 203/073F2F8622001699579F8FDB2F54CB7B
Comments
On 03/30/2006 at 3:32:07 PM MST Merlinox wrote:
1
I've to use md5 to crypt a string. But I need to crypt it using a simmetric key (ex.: 12345).
How I do it?
On 03/30/2006 at 4:08:31 PM MST Merlinox wrote:
2
Sorry. I've readed bad documentation. I've resolved problem with hash() and toBase64() CF Function.
Thanks
On 08/01/2006 at 10:27:04 AM MDT Anonymous wrote:
3
I have form.password element how do I getBytes() from there to pass it to <cfset result = digest.digest(str.getBytes())>
- Dear SQL Server Enterprise Manager Developer
- PostalMethods - Web Service for Snail Mail
- Mastering CFQUERYPARAM
- Google Code Search for ColdFusion
- Speaking at CFUNITED 2008
- Getting ColdFusion SQL Statements from SQL Server Trace
- CFSCRIPT Cheatsheet
- 3 New Image Effects for ColdFusion 8
Subscribe to my RSS Feed:
RSS
RSS
add to del.icio.us
Pete Freitag is a software engineer, and web developer located in










