• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 838
  • Last Modified:

COLDFUSION HASH SHA-256 QUESTION

hello experts
For the following code:
<cfset tmppassword = 123456789/>
<cfset uuid = '3C154913-EDA0-B54A-EEF3896EEC54EAAA'/>
<cfset password = hash(tmppassword & uuid ,"sha-256") />
<cfoutput>
#password#<br>
#len(password)#<br>
</cfoutput>
i'm getting a 64 char string and not a 44 char string.
(http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c52.html)
Any idea why?
0
Panos
Asked:
Panos
  • 2
  • 2
1 Solution
 
_agx_Commented:
The docs are wrong .. sort of.   "sha-256" generates 32 bytes

               <cfset bytes = binaryDecode(password, "hex")>
                in bytes = <cfdump var="#arrayLen(bytes)#">

When encoded as "hex" (the default) you get 64 chars:

              <cfset inHex = binaryEncode(bytes, "hex")>
               in hex = <cfdump var="#len(inHex)#">

You only get 44 chars when using "base64":
 
            <cfset inBase64 = binaryEncode(bytes, "base64")>
             in base64 = <cfdump var="#len(inBase64)#">

So your results are correct. The docs just failed to mention the *CF* results are always in hex. Therefore the expected length is 64, *NOT* 44.
0
 
PanosAuthor Commented:
Hi agx
Nice to see you again.
Thank you for your help.
0
 
PanosAuthor Commented:
Thank you
regards
panos
0
 
_agx_Commented:
Thanks, and you're welcome :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now