views:

1135

answers:

2

I'm trying to get an MD5 hash of a value in ColdFusion. I tried this code using the Encrypt function1:

<cfscript>
val = 1117;
md5 = Encrypt(val, 0, "MD5", "Hex");
</cfscript>

But I get an error:

The MD5 algorithm is not supported by the Security Provider you have chosen.

How can I choose a different security provider?


1 Yes, I know that MD5 isn't an encryption algorithm, but the ColdFusion folks don't seem to know that because they list it as a supported algorithm for the Encrypt function. Edit: I didn't see the built-in Hash function but I saw the fact that Encrypt lists md5 and sha as supposedly supported algorithms, so I thought (incorrectly it turns out) that this was just how you got a hash in CF.

+8  A: 

If you are wanting a hash shouldn't you try the hash function in ColdFusion? I end up using the SHA or SHA-256 algorithms, but the MD5 should work using that function.

hash(saltTheHash & trim(UserPassword), "SHA")

I would only use encrypt if you are wanting to decrypt sometime later. For things like passwords, you don't want to decrypt them so use the hash function instead.

Eddie
He should omit the SHA attribute (or use MD5, although it's default) to get the result he wants. For things *other* than file verification, though, I use SHA as well.
Ben Doom
thanks, i didn't see the hash function when i was browsing the list, and i saw MD5 in the encrypt function, so i thought that how you did it in cf.
Kip
+5  A: 

Use CF built in "Hash" function. It takes the following format:

Hash(string [, algorithm [, encoding ]])

The following works.

val = 1117; md5 = Hash(val, "MD5");

Bazza
oops, didn't even see that function. thanks!
Kip