Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 809
  • 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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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