'Generate the RSA key pair
Dim kpg As KeyPairGenerator
kpg.Initialize("RSA", 512)
kpg.GenerateKey
'Encrypt a string
Dim C As Cipher
Dim plainText As String = "Hello world, this is an RSA test"
C.Initialize("RSA/ECB/NoPadding")
Dim encrypted() As Byte = C.Encrypt(plainText.GetBytes("UTF8"), kpg.privateKey, False)
'Decrypt
Dim bc As ByteConverter
Dim decrypted As String = bc.StringFromBytes(C.Decrypt(encrypted, kpg.PublicKey, False), "UTF8")
ToastMessageShow(decrypted, True)