Xojo.Crypto.PBKDF2

From Xojo Documentation

Method

Xojo.Crypto.PBKDF2(salt As Xojo.Core.MemoryBlock, data As Xojo.Core.MemoryBlock, iterations As UInt32, desiredHashLength As UInteger, hashAlgorithm As HashAlgorithms) As Xojo.Core.MemoryBlock

Supported for all project types and targets.

Returns the PBKDF2 hash value of the data, first applying the salt value and using the specified hashAlgorithm. The iterations parameter is the number of loops that the hash algorithm does. The desiredHashLength parameter lets you specify the number of bytes that you want the resulting hash to be. 16 or 32 bytes are commonly used.

Notes

PBKDF2 is a "slow", i.e. deliberately processing intensive, algorithm for generating hash values. Slow is relative, for generating a single hash value it is plenty fast. The benefit of a slow algorithm is that it is impractical for hackers to generate hash tables using it because it would take too long to generate the thousands of hashes for commonly used values. Use a higher value for iterations to further slow the hash creation.

Refer to PBKDF2 on Wikipedia.

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)