Skip to content

Crypto Improvements

Xojo 2021 Release 3 has a few improvements to the Crypto module that you might find useful.

SHA3

A new SHA3 algorithm is available for use with the Hash function. You can now use SHA3-256 (SHA3 with 256-bit digest) and SHA3-512 (SHA3 with a 512 bit digest) from the Crypto.HashAlgorithms enumeration for stronger encryption or compatibility with something else that uses them.

Var hash As String
hash = Crypto.Hash("YourPasswordSentence", Crypto.HashAlgorithms.SHA3_512)

BlowFish / TwoFish

The BlowFish and TwoFish encryption algorithms can now be used in Xojo. These two algorithms are similar, with BlowFish being the original algorithm and TwoFish being a newer, more secure version that was derived from BlowFish.

You can use them in Xojo with the Crypto.BlowFishEncrypt, Crypto.BlowFishDecrypt, Crypto.TwoFishEncrypt and Crypto.TwoFishDecrypt methods.

You can use either to encrypt data, but in general you’ll want to avoid BlowFish for your own code, although it might prove useful for compatibility with other libraries or tools.

AES

AES (Advanced Encryption Standard) is also used to encrypt data. You can do this using the Crypto.AESEncrypt and Crypto.AESDecrypt methods. Here is a quick sample:

Var encrypted As MemoryBlock

Var dataToEncrypt As MemoryBlock = "Secret!"
Var key As MemoryBlock = Crypto.GenerateRandomBytes(16)
Var initVector As MemoryBlock = Crypto.GenerateRandomBytes(16)
encrypted = Crypto.AESEncrypt(key, dataToEncrypt, Crypto.BlockModes.CBC, initVector)

Var decrypted As MemoryBlock
decrypted = Crypto.AESDecrypt(key, encrypted, Crypto.BlockModes.CBC, initVector)
// decrypted = "Secret!"

CRC-32

CRC32 is just a simple way to test data integrity and is not cryptographically secure. It still has its uses for fast data comparison and simple hash tables. It can be called like this:

Var crc32 As String
crc32 = Crypto.Hash("StringOrDataToTest", Crypto.HashAlgorithms.CRC32)

RSASign

RSASign now takes an optional parameter and RSASignModes let you specify the hash to use.

Learn more about the Crypto module in the Xojo Documentation.

Updated (Nov 22, 2021): Added AES section