How to get raw binary from hash function in ColdFusion 9?

406 views Asked by At

In ColdFusion 9, I am hashing a string like so: hash("bob", "SHA1"), I need it to return binary instead of a hex string.

2

There are 2 answers

0
Leigh On BEST ANSWER

Since you know the hashed string is in hex, simply decode it with the aptly named binaryDecode() function.

hashedString = hash("bob", "SHA1");
binaryData = binaryDecode(hashedString , "Hex");
1
Adam Cameron On

Is this the sort of thing yer after?

<cfscript>
s = "G'day World";
hash1 = hash(s, "SHA-1");
bin = binaryDecode(hash1, "hex");
hash2 = binaryEncode(bin, "hex");

writeDump(variables);
</cfscript>

output of code

Docs: