string to SHA encoding?

Does anyone know of any examples regarding displaying SHA-1, SHA-3, SHA-256, or SHA-512 hashes, from a text string?
(This needs to be done without plugins of any kind).


Those are built in to the new Crypto module.

and there are 3rd party implementations also.

when you say NEW crypto module, does this mean it is not in Xojo 2013 r3.1.

I am not sure when it was added. either late 2013 or early 2014, if my memory serves me correctly.

I guess I’ll have to wait and hope Norman reads this thread.

Thank you both.

You can open up Feedback and check the release notes.

Thanks Brad, I’ll try that.

Crypto was added in 2012. 2012r2 added SHA1, SHA256 and SHA512.

Thanks everyone - much appreciated!

When using the Crypto function to hash a string, what type of Encoding do I need to use in order to display the result in a TextField correctly?

ASCII, and UTF8 give me the dreaded black triangles (indicating wrong encoding type).
UTF16 returns Chinese characters.
UTF32 returns accented european characters.

Dim HashStringMD5 As String HashStringMD5 = Crypto.Hash("TextField1.text", Crypto.Algorithm.MD5) MD5Field.text = ConvertEncoding(HashStringMD5, Encodings.UTF8 )

I also tried:

Dim HashStringMD5 As String HashStringMD5 = DefineEncoding(Crypto.Hash("TextField1.text", Crypto.Algorithm.MD5),Encodings.UTF8 ) MD5Field.text = ConvertEncoding(HashStringMD5, Encodings.UTF8 )

Encoding isn’t the issue. You are getting back a series if bytes not meant to be human-readable. If you convert the encoding, you will change those bytes and destroy the hash.

As with any series of bytes, if you want to examine them in the UI, covert to hex first with EncodeHex.

Thanks Kem - I will try that.

I am now using the following code:

Dim HashStringMD5 As String = Crypto.Hash("TextField1.text", Crypto.Algorithm.MD5) MD5Field.text = EncodeHex(HashStringMD5)

My app now shows the MD5 hash of hello world as:

But other software I have shows the MD5 hash of hello world as:

Also just noticed that even when I change the input string to something completely different - the MD5 hash stays the same??

Totally confused now??

You put TextField1.text into quotes. :slight_smile:


I hate being me :frowning:

Is there any reason a hash should be upper, or lower case, - or is it irrelevant?


Thank you.

To elaborate, the hash is neither since it’s just a series of bytes. Since the hex version is for human viewing only, it’s irrelevant.