The RSA_PUBLIC_KEY function generates the unique public key from a private key using the RSA asymmetric cryptosystem, which requires a public key to encrypt and a private key to decrypt. As denoted by their names, the public key is shared with others, while the private key should be kept secret. The private key may be generated using the RSA_PRIVATE_KEY function. IDL strings may be encrypted and decrypted using the IDL_String::Decrypt/Encrypt methods.

Examples


Generate a public/private key pair, and use them to encrypt and decrypt an IDL string.

privateKey = RSA_PRIVATE_KEY(2048)
publicKey = RSA_PUBLIC_KEY(privateKey)
 
mystring = "IDL is awesome!"
wellkeptsecret = mystring.Encrypt(publicKey)
print, wellkeptsecret
print, wellkeptsecret.Decrypt(privateKey)

IDL prints:

hmXf4Y1cr/60ofSooRvSTPtite7bS6mJsI9lgfgUOz328vndELb8z9L3htVfWRxEYW...
 
IDL is awesome!

Note: Because of the built-in randomness of RSA, calling the Encrypt method again on the same string will give a different result for each call.

Syntax


Result = RSA_PUBLIC_KEY( PrivateKey )

Return Value


The result is a scalar string containing the public key in PEM X.509/SubjectPublicKeyInfo format. This format begins with the characters "-----BEGIN PUBLIC KEY-----" and contains the public key as a scalar string with lines separated by newline (\n) characters.

Arguments


PrivateKey

Set this argument to a scalar string or string array containing the RSA private key. PrivateKey should be an RSA Private Key in the PEM format (either PKCS1 or PKCS8):

-----BEGIN PRIVATE KEY-----
MIIBOQIBAAJBAPOXacw2mXRlHhP8xBfwm+7GPKnPb6lqDfWdo/HWRj8qmezUMa28
0n7s1LUBWkbJ7l13vcZCyfaDsL7FEqIHqwsCAw...
-----END PRIVATE KEY-----

If PrivateKey is a scalar string then all of the lines should be joined together with newline (ASCII code 10) characters. PrivateKey can also be specified as a string array containing the individual lines.

Keywords


None

Version History


8.8.3

Introduced

See Also


IDL_String::Decrypt/Encrypt, RSA_PRIVATE_KEY