Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 229
Trololololol Avatar asked Jan 01 '26 07:01

Trololololol


2 Answers

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");
like image 169
Leigh Avatar answered Jan 06 '26 10:01

Leigh


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:

  • BinaryDecode()
  • BinaryEncode()
like image 40
Adam Cameron Avatar answered Jan 06 '26 11:01

Adam Cameron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!