Sample code for 30+ languages & platforms
CkPython

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 CkPython Downloads

CkPython
import sys
import chilkat

success = False

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

pubkey = chilkat.CkPublicKey()

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

rsa = chilkat.CkRsa()

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

rsa.put_EncodingMode("base64")

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

print(encryptedStr)