Crypto.RSAEncrypt

From Xojo Documentation

Method

Crypto.RSAEncrypt(Data As MemoryBlock, PublicKey As String) As MemoryBlock

New in 2013r4

Supported for all project types and targets.

Encrypts the data using the specified PublicKey.

Notes

Attempting to encrypt using a PrivateKey raises a CryptoException.

Sample Code

Encrypt some text:

Var privateKey As String
Var publicKey As String

If Crypto.RSAGenerateKeyPair( 1024, privateKey, publicKey ) Then
// 1024-bit private and public keys were generated

Const kMessage = "this is a test"

Var msg As New MemoryBlock(14)
msg.StringValue(0, 14) = kMessage

// Encrypt msg using the publicKey
Var encryptedData As MemoryBlock = Crypto.RSAEncrypt( msg, publicKey )

If encryptedData <> Nil Then
MessageBox("Successfully encrypted.")
End If
End If