MD5 on Text

Hey everyone,

lets say i have got a variable x As Text
How do I converte this to a MD5 Hash using Xojo iOS

http://developer.xojo.com/crypto$MD5

Hey Jason,
Thanks for your answer. I’ve already seen this thread, but I’m confused because all of these Methods are working with Memoryblocks.

Tried that
dim a As MemoryBlock = TextEncoding.UTF8.ConvertTextToData(“test”)
dim b As MemoryBlock = Xojo.Crypto.MD5(a)
dim c As Text = TextEncoding.UTF8.ConvertDataToText(b)

But it didn’t work - RunTimeExeption

The bytes involved in a MD5 hash are not going to be a valid UTF8 encoding, so you’re getting an error on that last line. You could change the last line to be an ASCII encoding instead of UTF8 if you don’t care about that. What are you trying to accomplish by getting the MD5 of the string- perhaps there’s another way to do what you want to do in the end…

@Travis Hill Thanks for your answer
You are right, but it’s as you thought, not what I wanna get :smiley:

I simply what to convert a Text like “test” to its MD5 Hash -> 098f6bcd4621d373cade4e832627b4f6

get a function to convert memoryblock to hex text :slight_smile:

not that difficult and maybe a good exercise?

Function MD5(extends t as Text) As Text dim a As MemoryBlock = TextEncoding.UTF8.ConvertTextToData(t) dim b As MemoryBlock = Xojo.Crypto.MD5(a) dim v() as Text dim n as UInteger=b.Size-1 for i as UInteger=0 to n v.Append b.UInt8Value(i).ToHex(2) next return text.Join(v,"") End Function

@Antonio Rinaldi
Thank your very much!