xojo.crypto.generateRandomBytes

Having an issue w/ crypto.generateRandomBytes under the new framework using the latest release (2015r2.2). Here is my code:

[code]using xojo.core
using xojo.crypto

dim myRandomBytes as memoryBlock

myRandomBytes = crypto.generateRandomBytes(15)[/code]

When I mouseOver the crypto.generateRandomBytes, the status says it is to return a xojo.Core.memoryBlock (as does the documentation); however, when I run this I get the following error:

Type mismatch error. Expected class xojo.Core.MemoryBlock, but got class MemoryBlock
myRandomBytes= crypto.generateRandomBytes(15)

If I remove/comment out the using xojo.core line, and make the dim reference just a standard memoryBlock from the old framework, it runs just fine. Am I doing something wrong?

Your Using clause says Xojo.Crypto but Xojo.Crypto.Crypto.GenerateRandomBytes does not exist so it goes to the global Crypto.GenerateRandomBytes instead.

I don’t use Using clauses at all. I would write this code as

Dim MyRandomBytes As Xojo.Core.MemoryBlock = Xojo.Crypto.GenerateRandomBytes(15)

Which will work perfectly. Though in theory (have not tried it) setting the Using clauses to

Using Xojo.Core Using Xojo

would do the trick.

EDIT: Actually, now it gives a runtime error when I try that suggestion:

Runtime Error
Please report what caused this error along with the information below.
Common\ObjectGlue.cpp: 168
Failure Condition: mClassPtr
Xojo.Core.MemoryBlock

Here’s what I have in a console app (under the Run event handler), under Windows, which is causing the crash [no other code exists in the project]:

[code]dim myRandomBytes as xojo.core.memoryBlock = xojo.crypto.generateRandomBytes(8)

do
app.doEvents()
loop[/code]

That doesn’t sound like fun.

Hahaha… it’s not, I assure you. I need this to work, along w/ this issue I reported a couple months ago:

39191 - hashAlgorithms.sha512 breaks core.crypto.pbkdf2

I was beginning to think the new framework didn’t like me… now I’m thinking it’s just not stable enough to use atm. I know I can revert back to the old one; however, it’s a tough draw when you want to start getting used to programming the way Xojo will eventually require (and have your code in a state where it’ll already be syntax’d correctly to fit the new framework when dealing with updates to your code). I don’t like to fall back on the old if I don’t have to. Looks like I’m going to have to…

Makes me sad.

This may be platform-specific. Take a look at my Authentication Kit, which does exactly this without issue on OS X.

[quote=197340:@Eric Brown]Hahaha… it’s not, I assure you. I need this to work, along w/ this issue I reported a couple months ago:
39191 - hashAlgorithms.sha512 breaks core.crypto.pbkdf2
[/quote]

I can’t replicate that:

[code]
Using xojo.core
Using xojo.crypto

Dim SaltValue As MemoryBlock = TextEncoding.UTF8.ConvertTextToData(“SaltValue”)
Dim DataValue As MemoryBlock =TextEncoding.UTF8.ConvertTextToData(“MyDataGoesHere”)
Dim Hash1 As MemoryBlock =PBKDF2(SaltValue, DataValue, 100, 32, HashAlgorithms.SHA512)[/code]

Hash1 always has the same value in the end for me.

[quote=197366:@Travis Hill]I can’t replicate that:

[code]
Using xojo.core
Using xojo.crypto

Dim SaltValue As MemoryBlock = TextEncoding.UTF8.ConvertTextToData(“SaltValue”)
Dim DataValue As MemoryBlock =TextEncoding.UTF8.ConvertTextToData(“MyDataGoesHere”)
Dim Hash1 As MemoryBlock =PBKDF2(SaltValue, DataValue, 100, 32, HashAlgorithms.SHA512)[/code]

Hash1 always has the same value in the end for me.[/quote]

It doesn’t for me. I copied your code exactly… and put into a Windows console file in the Run Event:

[code] Using xojo.core
Using xojo.crypto

Dim SaltValue As MemoryBlock = TextEncoding.UTF8.ConvertTextToData(“SaltValue”)
Dim DataValue As MemoryBlock =TextEncoding.UTF8.ConvertTextToData(“MyDataGoesHere”)
Dim Hash1 As MemoryBlock =PBKDF2(SaltValue, DataValue, 100, 32, HashAlgorithms.SHA512)

print hash1.UInt64Value(0).toText

do
app.doEvents()
loop[/code]

The first 8 bytes of that (which is all I print out) change every time I run it.

Added to my reply, if I change the hash to SHA256… it stays the same, as expected.

Ah- a Windows console app. That wasn’t clear from the Feedback case. Does it work OK for you from a Windows desktop app?

Nope… same issue.

Added a label1 to the window, and put in the window1 open event handler:

[code] Using xojo.core
Using xojo.crypto

Dim SaltValue As MemoryBlock = TextEncoding.UTF8.ConvertTextToData(“SaltValue”)
Dim DataValue As MemoryBlock = TextEncoding.UTF8.ConvertTextToData(“MyDataGoesHere”)
Dim Hash1 As MemoryBlock = PBKDF2(SaltValue, DataValue, 100, 32, HashAlgorithms.SHA512)

label1.text = hash1.UInt64Value(0).toText[/code]

Changes every time I re-run the application.

What version of Xojo and Windows? Is there any difference if you build and then run the built executable?

If you could attach your project to the case, I’d appreciate it. I’d like to nail this one down, but there’s some gap between what we’re seeing. I’ll move further discussion over to the case itself.

I’m using Xojo 2015r2.2 and Windows 8.1 Enterprise. Give me a few, and I’ll attempt to create and attach a project to the feedback. Thanks for your help, Travis!

EDIT: By the way, compiling the applications and running them still result in the unexpected broken behavior.

Alright, not sure how to attach in Feedback… here is a console project I made that reflects the problem:

https://dl.dropboxusercontent.com/u/13574877/cryptoExample.xojo_binary_project

app.DoEvents in a GUI app?

No