Posted on 2012-08-17
Last Modified: 2012-08-17
hello experts
For the following code:
<cfset tmppassword = 123456789/>
<cfset uuid = '3C154913-EDA0-B54A-EEF3896EEC54EAAA'/>
<cfset password = hash(tmppassword & uuid ,"sha-256") />
i'm getting a 64 char string and not a 44 char string.
Any idea why?
Question by:Panos
    LVL 51

    Accepted Solution

    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.
    LVL 2

    Author Comment

    Hi agx
    Nice to see you again.
    Thank you for your help.
    LVL 2

    Author Closing Comment

    Thank you
    LVL 51

    Expert Comment

    Thanks, and you're welcome :)

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
    This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
    This video discusses moving either the default database or any database to a new volume.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now