Crypto RSA Question

I have been working with the Crypto RSA Example and everything works well as written. Where I am having a problem is with the decrypt using the Public Key when built on a different Window as if on the receiving end of the process.

Using a second window I have a text area for placing the excrypted data, and I bring over the Public Key into a second text area. What I am trying to do is read the encrypted data and make it into decrypted data and show this is a third text area. In other words, in one window I encrypt “How now brown cow.” I then copy the encrypted data of this and in the second window I place the encrypted data and also the Public Key. I then have a button for “Read Data”. The result should be “How now brown cow.”

I’ve set the following code to do the above but am unsure that I’m pursuing this correctly.

Dim publicKey as String
Dim encryptedDara as String

// Set value of the publicKey
publicKey = PublicKeyArea.text // using a textArea to hold public key

// Decrypt message
encryptedData =publicKeyArea.text
Dim decryptedData as MemoryBlock = CryptoRSADecrypt(encryptedData, publicKey)
taOpenMessage.text = decryptedData.stringValue // using a textArea to show decrypted message “How now brown cow.”

Can anyone tell me if I’m on the right path? The code doesn’t work; I get a CryptoException BER Decode Error. I haven’t found out what that exactly means yet. If you could point me in the right direction I’d greatly appreciate the help. Thank you.

Just looking over your code really quickly you need to decrypt with the private key. You encrypt with the public key. Try this blog: http://blog.xojo.com/2014/02/05/using_publicprivate_key_encryption/ it might help you.