Sample code for 30+ languages & platforms
Chilkat2-Python

Use Base64 RSA Key to Encrypt

See more RSA Examples

Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.

Chilkat Chilkat2-Python Downloads

Chilkat2-Python
import sys
import chilkat2

success = False

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

pubkey = chilkat2.PublicKey()

success = pubkey.LoadBase64("MIICdgIBADA ... A9PXLk+j5A==")
if (success == False):
    print(pubkey.LastErrorText)
    sys.exit()

rsa = chilkat2.Rsa()

success = rsa.UsePublicKey(pubkey)
if (success == False):
    print(rsa.LastErrorText)
    sys.exit()

rsa.EncodingMode = "base64"

encryptedStr = rsa.EncryptStringENC("12345678",False)

print(encryptedStr)