xojo.core.crypto.pbkdf2 not consistent?

I’m having a major problem with a piece of code, using the new xojo.core.crypto.pbkdf2 function. The outcome is different each time, although the hash data remains the same. Could somebody see if this is a error in code, or if the pbkdf2 is broke (a hash should remain the same, if the data passed to it remains the same as well):

[code]function cipher(plainText as text, cipherPass as text, cipherIterations as uInt32) As text

using xojo.core
using xojo.crypto

dim convertedText as memoryBlock
dim cipherSalt as memoryBlock
dim cipherPad as memoryBlock

convertedText = textEncoding.utf8.convertTextToData(cipherPass)
cipherSalt = textEncoding.utf8.convertTextToData(“this is my salt”)

cipherPad = pbkdf2( _
cipherSalt, _
convertedText, _
cipherIterations, _
plainText.length, _

return hex(cipherPad.uInt8Value(0)).toText

end function[/code]

Here, I’m simply just returning the first uInt8Value of cipherPad just to demonstrate its contents change every time the function is called, even if plainText, cipherPass, and cipherIterations remain the same. So, if you called cipher(“123”, “123”, 3)… you’d get a different outcome every time.

cipherPad should not be changing every time, as its contents are the hash return using the new framework pbkdf2 function.

Narrowed it down to the ‘hashAlgorithms.sha512’ part of the pbkdf2. If you change it to SHA1 or SHA256… the hash return functions as it should.

Have you tried plain SHA512 hashing to make sure its results are consistent? Just curious if the bug is there and not in pbkdf2.


The sha512 hash itself seems to be working as intended… it’s only when it’s used as the algorithm parameter in the pbkdf2 function that is not.