Hi Jason,
> I've got this working, but it returns a blob with 32 "octets". Looks just
> like an array. Probably dumb question, but how do I turn this into a text
> variable? I tried Blob to Text and Blob to Variable with no luck.
That’s right, the method I posted returns the hashed value as a blob.
The human readable format of a SHA256 hash would take each bit of the hashed
value (blob) and convert the decimal to hex and the return a concatenation of
each hex bit.
Here is some sample code to convert the blob to hex_string:
// get the hashed_blob of "test"
C_BLOB($hashed_blob)
$hashed_blob:=UTIL_hash_sha256 ("test")
// convert blob to hex string
C_TEXT($hex_string;$thisHex)
$hex_string:=""
For ($a;1;BLOB size($hashed_blob))
$thisHex:=UTIL_DECTOHEX ($hashed_blob{$a-1})
$hex_string:=$hex_string+$thisHex
End for
alert($hex_string)
The code behind UTIL_DECTOHEX is here:
// ----------------------------------------------------
// Method: UTIL_DECTOHEX
// Example: $var_hex_text:=UTIL_DECTOHEX($var_longint)
// Description: Converts a longint (77) to a hexadecimal string ("4D")
// Parameters:
// $0 := Text
// $1 := Long Int
// ----------------------------------------------------
C_LONGINT($1)
C_TEXT($0;$hex)
C_BOOLEAN($done)
If (Count parameters=1)
$hex:=Substring(String($1;"&x");3)
$done:=False
Repeat
If (Length($hex)>1)
// length greater than 1
If (Substring($hex;1;1)="0")
// starts with 0
$hex:=Substring($hex;2)
Else
// doesn't start with 0
$done:=True
End if
Else
// length of 1
$done:=True
End if
Until ($done)
$0:=$hex
End if
For me, the above code converts "test" to
9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2BB822CD15D6C15B0F0A8 which matches the
output found here:
http://md5decrypt.net/en/Sha256/
Sha256(test) = 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
Hope that helps!
Kind Regards,
Tim PENNER
Timothy Penner
Technical Services Engineer
4D Inc
95 S. Market Street, Suite #240
CA 95113 San Jose
United States
Téléphone : +1-408-557-4600
Standard : +1-408-557-4600
Fax : +1-408-271-5080
Email : [email protected]
Web : www.4D.com
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ: http://lists.4d.com/faqnug.html
Archive: http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************