Translating an RSA Public Key From Non-Xojo Program

I’ve been asking some questions about handling RSA encryption on Xojo and I thank everyone who has helped me!

I managed to get communication to work where the Xojo public key is sent to the remote system, and that remote system can encrypt with that key and send it back to the Xojo program where it can be read. Half the battle is won, it seems.

Now I’m trying to get the public key from the non-Xojo program to transfer to the Xojo program, and have it translate the key for use in encrypting messages to send back to the non-Xojo program.

As it stands, when I try encrypting a string with

EncryptedMsg = Crypto.RSAEncrypt(TextFieldInput.Value, ModEncrypt.RemotePubKey)

…I get “BER decode error 1”

I suspect it’s something in the format of the generated key sent to the Xojo program. In Go, it’s generated using:

[code]pubASN1, _ := x509.MarshalPKIXPublicKey(keyPublic)

btBytes := pem.EncodeToMemory(
	&pem.Block{
		Type:  "RSA PUBLIC KEY",
		Bytes: pubASN1,
	},
)[/code]

When sent to the client (Xojo) program, this is a sample public key generated:

[quote]-----BEGIN RSA PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA0f+tqqgC5lU4gEYUXTzS
nxopshFsFQGMcwUAylsZTnDU7yHbjhPJ1/4U7R4uBh+PWIgI+ARwh1iVFoAxoPuW
BLux5g218OMRwpBv2ZmOMt54UPERuXlLc0TLFDznn34VvdDQ6oIqhMrplbci1ITI
BZV0mtgjYBFezyy0Kt3ngnA3QPfazu2ttlNJggSTENQ6KMPhoY7AQUv1J9Z2KhZS
WLIf7pvQq1DhXjoI3pdCejyZdwXm1e9WuOLrHqa22TxCZGlBb0VdIpp0pIulCZ5y
JqBkwkHn4yc81DKrktU4CiuR8R+Cd8gR1PYvXrf7kiq29mF08ssvWy4rPz52jVe2
kVslxwOA9baBx1D32eGXKU49+NQeMtGYmRKsAjgLWEaTMMqtuq3r0LmvDODBHiol
OPxgthIir5NLblB7qcYr2VXwrBbTuLa72/kmiQFCOR94unpSxGMJulxFhce3yjww
pvY0o8mmwtZWK4wXS6Is5n1su6nFzdU2ra9HqSSkUgNmTA8ZEbwzBJNHz1n8+01I
JRC0sPuMMi5KV2VmVrFv1uY6WkUYsbRDthCUwxX88ARrGjt4jC2l5E+iMCDnUYTk
0qAiFaFXmHRoma1k08k+HhHIsv9tHrKxWJp9Qa9VwQvB3YTCzv2fPxbG0uAhjgky
gODouzmP1cQNMTuLqENsF7cCAwEAAQ==
-----END RSA PUBLIC KEY-----[/quote]

Is what’s happening something with the Go program generating a key with DER when Xojo wants BER? Does anyone see something that stands out in the generation of the key sent to Xojo that the basic Crypto.RSAEncrypt() isn’t able to properly translate?

Take a look at my PEM* methods in https://github.com/thommcgrath/Beacon/blob/master/Project/Modules/BeaconEncryption.xojo_code for some inspiration.

I don’t know if it would be of help with your case, but I published an article about RSA interchange between Xojo and PHP time ago here.