Kip
Kip

Reputation: 109397

How can I get an MD5 hash in ColdFusion?

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.

Upvotes: 6

Views: 13549

Answers (2)

Barry Jordan
Barry Jordan

Reputation: 2706

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

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

The following works:

<cfscript>
    val = 1117;
    md5 = Hash(val, "MD5");
</cfscript>

Upvotes: 7

Eddie
Eddie

Reputation: 5080

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.

Upvotes: 16

Related Questions