A LONG while back I was testing the Hash function of ColdFusion 10 (during the Beta program) and I wrote a small test script to let me quickly check all the Hash algorithms. I did the same thing when I was testing the Encrypt and Decrypt functions to and I posted that script in this post. As I was sifting through scraps of code to I saw the Hash test script I wrote and figured I should share that one too.

This little snippet of code lets you test with the MD5 and the various strengths of SHA hashes. It also has the default CFMX_COMPAT algorithm that you should NEVER use. Additionally MD5 has been proven hackable and is reversible in many cases with rainbow tables.

I believe these are all ColdFusion 9 and up, but I may be wrong. It's been a while and I don't remember.

So I hereby set this code free into the wind!

view plain print about
1<cfparam name="form.data" default="">
2<cfparam name="form.hashType" default="">
6 <title>Hash Me</title>
9<form action="hash.cfm" method="post">
10 Data to Hash:<cfoutput><input type="text" name="data" value="#form.data#" size="40"></cfoutput><br />
11 Method:<select name="hashType" size="1">
12 <option value="CFMX_COMPAT"<cfif form.hashType eq "CFMX_COMPAT"> selected</cfif>>CFMX_COMPAT</option>
13 <option value="md5"<cfif form.hashType eq "md5"> selected</cfif>>MD5</option>
14 <option value="sha"<cfif form.hashType eq "SHA"> selected</cfif>>SHA</option>
15 <option value="SHA-256"<cfif form.hashType eq "SHA-256"> selected</cfif>>SHA-256</option>
16 <option value="SHA-384"<cfif form.hashType eq "SHA-384"> selected</cfif>>SHA-384</option>
17 <option value="SHA-512"<cfif form.hashType eq "SHA-512"> selected</cfif>>SHA-512</option>
18 </select><br />
19 <input type="submit" name="submit" value="Hash This">
22<cfif Len(trim(form.data)) and Len(trim(form.hashType))>
23 <cfoutput>
24 #form.data# encrypted with #form.hashType# is<br />
25 #hash(form.data,form.hashType)#</cfoutput>

*Note: When I write little tools like this I'm usually writing it because there is something I absolutely need to see in order to complete another project. These little tools are not written as projects themselves and therefore may not be very pretty or as full featured as something that I was writing as a complete project. I just needed to get some code running that gave me back the data I needed to see. There are no warranties or promises. If you find is useful then great. If not, oh well. I know the code works on CF9 at the moment. I can not be certain if it still works on other versions of ColdFusion. * Any code posted may not be totally secure or production ready. Use at your own risk. ** Unless otherwise noted, this code shall be deemed Public Domain.