Xojo.Core.TextCoding Issues

Hi,

I am still struggling with some of the new framework as I can’t find a suitable TextEncoding option for my Hash that I am creating. I still get a “Exception:
The data could not be converted to text with this encoding.”.

I have tried ASCII and UTF-8 with no luck as the hashed characters are definitely causing this. Using the new framework does anyone have any suggestions to properly encoding a SHA512 hash?

I need to get the hash back to a text type so I can compare it.

Thanks
Mike

CreateHash(passwordMB as Xojo.Core.MemoryBlock, saltMB as xojo.Core.MemoryBlock) as Xojo.Core.MemoryBlock
  Using Xojo.Core
  Using Xojo.Crypto
  Dim thisHash As MemoryBlock = PBKDF2(SaltMB, PasswordMB, 100, 16, HashAlgorithms.SHA512)
  Return thisHash
Dim NewHashMB as MemoryBlock = CreateHash(usersTypedInPasswordMB, testSaltMB)
// EXCEPTION RAISED BELOW
Dim usersNewTypedInHashText as Text = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(NewHashMB)

[quote=232540:@Mike Cotrone]Dim NewHashMB as MemoryBlock = CreateHash(usersTypedInPasswordMB, testSaltMB)
// EXCEPTION RAISED BELOW
Dim usersNewTypedInHashText as Text = Xojo.Core.TextEncoding.UTF8.ConvertDataToText(NewHashMB)[/quote]

A hash is arbitrary bytes and by no means textual. Why do you want it as a Text?

In the old framework that is how I compared new typed in hash to the db hash. I am not aware of how to compare MB directly so this may be my lack of understanding how to properly compare MB. How should I go about this Joe?

Thanks!

You can just compare two Xojo.Core.MemoryBlocks against each other with the normal relational operators.

Ha! Thanks Joe! Naturally I thought for some reason it was harder than that. :slight_smile:

Thanks again Joe!

The “Class Summary” of Xojo.Core.MemoryBlock doesn’t show that the comparison is implemented. You have to scroll to the bottom of all class members to stumble upon it.

ITs pretty clearly written, but I never did scroll down that far on the page. That is my fault :slight_smile:

Operators
= (Comparison)
MemoryBlocks can be compared with each other using the “=” operator.

Notes
MemoryBlocks are considered equal for these conditions:

The MemoryBlocks are the same object
Both MemoryBlocks’ data point to the same location
Both MemoryBlocks’ size and content are the same
There is no concept of one MemoryBlock being greater than or less than another MemoryBlock.