Xojo Crypto issues on Sierra

Greetings,

I have the latest Xojo, and Sierra, I tried to use the Crypto part and copy / paste the code from developer.xojo.com and from start I get errors .

For example for the HASH part I have the code from the website

Using Xojo.Core Using Xojo.Crypto Dim hash As MemoryBlock hash = Hash("YourPasswordSentence", Crypto.HashAlgorithms.SHA512)

and I get the error

Crypto.HashAlgorithms     - This item does not exist

Any idea why ?

Well it seems that Using is Broken or something like that , among that if I put Xojo. in front of Crypto.HashAlgorithms.SHA512 it`s ok, so that Using it breaks at some point

Don’t bother with Using. I think the issue you’re having is you specified Using Xojo.Crypto and then call Crypto.HashAlgorithms which looks for Xojo.Crypto.Crypto.HashAlgorithms and thus, won’t be found.

Well I`m confuse,

Any idea how to make this work and output the data into a text box or something ?

And to have as well password and salt imputed from the interface ?

[code]Sample Code
Using Xojo.Core
Using Xojo.Crypto

Dim salt As Text = “SaltValue”
Dim saltMB As MemoryBlock
saltMB = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(salt)

Dim password As Text = “YourPasswordSentence”
Dim passwordMB As MemoryBlock
passwordMB = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(password)

Dim hash As MemoryBlock
hash = PBKDF2(saltMB, passwordMB, 100, 32, HashAlgorithms.SHA512)[/code]

It seems that this MemoryBlock goes nuts, I wish we actually had working samples on the docs and into examples.

Thanks in advance

And what is weird about that Crypto and new Xojo is that for example here in the docs I have the following :

[quote]MD5(data As MemoryBlock) As MemoryBlock
Generates the MD5 message-digest value of the data.[/quote]

so in my code I use :

[code] Using Xojo.Core
Using Xojo.Crypto

taResponse.Text = EncodeHex(MD5(tfPassword.Text))[/code]

where the data it comes directly from the text field, but when I do same thing with the PBKDF2 it throws an error telling me that it expects Memory block but it got String.

IS THERE something wrong in that Crypto or not ? I mean on one function Memory Block works properly and on the other side does not work .

Thanks

Assuming a method with Password As Text parameter and returns a Text. In the real world, you’ll likely want to set the salt as a ByRef parameter.

Dim Salt As Xojo.Core.MemoryBlock = Xojo.Crypto.GenerateRandomBytes(32) Dim PassBytes As Xojo.Core.MemoryBlock = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(Password) Dim Hash As Xojo.Core.MemoryBlock = Xojo.Crypto.PBKDF2(Salt, PassBytes, 12000, 64, Xojo.Crypto.HashAlgorithms.SHA512) Dim HashChars() As Text For I As Integer = 0 To Hash.Size - 1 Dim Value As UInt8 = Hash.UInt8Value(I) HashChars.Append(Value.ToHex(2)) Next Return Text.Join(HashChars, "")

Wrote in-browser, hopefully I got it right. I think your problem is Using, it’s getting you mixed up between the modern and legacy frameworks.

Also a couple tips. You should (but are not required to) match the key length in PBKDF2 to the length of the hash. SHA512 is 64 bytes for reference. You can figure this out pretty quickly by hashing anything, even an empty string, and using the size of the returned memoryblock. 100 iterations is also uselessly low. You should time some values on expected hardware and shoot for 0.25 to 0.50 seconds.

If you don’t need to use the modern framework, you can save yourself a little effort by using the legacy framework, which has EncodeHex and DecodeHex functions. The modern framework makes you do this on your own, which isn’t difficult, but is tedious.

well I noticed that now, the idea is other, I recently backed up my Mac on a apparently encrypted drive which uses 2 keys to have a generated password, and as a idiot I did not noticed, backed up the Mac, then format it and did a fresh install with sierra, when to restore I realise that the drive is encrypted, I did not noticed at the time as the password it was saved in keychain which is another issue as it suppose to be updated in the iCloud .

So I ended up with a clean pc, and all my data locked on a portable drive,

Why I`m trying to make those examples from crypto work as I remember that the password was generated with a Xojo example , and using some data that I have , so I have the password and I have the salt and I need the final password.

That was the whole idea.

Thanks again for help .

I remember that I had issues with that MemoryBlock as well until I found a solution and in the end it worked so I had that password generated and store it in Keychain now I just have to see how I can replicate that app that I did and find out my password .

I know it`s idiotic and stupid but what to do , it happened. so just try to find a solution for it .

Oh…

If you get access to your machine, I recommend keeping it simpler. Grab a copy of 1Password, have it generate your password, and save it. Select a strong master password that you can remember and you’ll never lose access to anything again. Don’t overthink it.

[quote=294166:@Thom McGrath]Oh…

If you get access to your machine, I recommend keeping it simpler. Grab a copy of 1Password, have it generate your password, and save it. Select a strong master password that you can remember and you’ll never lose access to anything again. Don’t overthink it.[/quote]

Well that is the next step, first I have to recover my data , so to have those examples functional

If it was the machine drive, doesn’t Apple offer to back up your encryption key to iCloud so you can unlock it with your iCloud account?

They do. I personally don’t opt in to that though. Seems counter to the purpose of whole-disk encryption to give Apple your encryption key.

Well its an external drive used for backup, but what I dont understand is that the password was saved in Keychain and the keychain was specifically set to be synced over iCloud, so theoretically I should get that damn password.

Anyway, I found my app used to generate the password but still I dont remember the password and the salt so its useless , and the bad side is that I have the compiled one only so I cannot even see what I wrote there

Thanks guys .