EncodeHex in new framework

Is there a way to accomplish this in the new framework? Not sure if I’m on the right track.

Dim encPwd As String = EncodeHex(HashText(txtPassword.Text, "SHA512"), False)

What I have…just don’t know how to “EncodeHex” tHash.

[code]Dim pHash As Xojo.Core.MemoryBlock
pHash = Xojo.Crypto.Hash(Xojo.Core.TextEncoding.UTF8.ConvertTextToData(txtPassword.Text), Xojo.Crypto.HashAlgorithms.SHA512 )

Dim tHash As Text
tHash = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(hash, True)[/code]

See here first part, you read how it works:
http://developer.xojo.com/xojo-core-memoryblock

My free M_Text module contains EncodeHex and much more.

http://www.mactechnologies.com/index.php?page=downloads#m_text

Thanx Kem & Derk. I struggled with the Xojo.core.memoryblock in that it wouldn’t return the hex the same as existing data in my DB.

I finally worked it out like this.

[code]Dim pHash As Xojo.Core.MemoryBlock
pHash = Xojo.Crypto.Hash(Xojo.Core.TextEncoding.UTF8.ConvertTextToData(txtPassword.Text), Xojo.Crypto.HashAlgorithms.SHA512 )

Dim hPWD As Text
hPWD = MemToHex(pHash)
[/code]

Here’s the MemToHex function I found in a blog somewhere or a post here. I can’t remember so I can’t take credit for it.

[code]Public Function MemToHex(mem As Xojo.Core.MemoryBlock) as Text
if mem = nil or mem.Size < 1 then return “”

static map() As Text //prebuild lookup
if map.Ubound < 0 then
redim map(65535)
dim s As Text
for i As integer = 0 to 65535
s = i.ToHex(4)
map(i) = s.Right(2) + s.Left(2)
next
end

dim dingle As integer = mem.Size mod 2 //even 0, odd 1
dim last As integer = (mem.Size - 2) \ 2 //last 2 byte index to lookup
dim elem As integer = last + dingle //last array index

dim r() As Text //result array, presized
redim r(elem)

dim p As Ptr = mem.Data //quicker view
for i As integer = 0 to last //map each 2 byte value
r(i) = map( p.UInt16(i*2) )
next

if dingle = 1 then r(elem) = p.UInt8(mem.Size-1).ToHex(2) //add possible trailing byte

return Text.Join(r, “”)

End Function
[/code]