Sample code for 30+ languages & platforms
Lianja

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

Lianja
llSuccess = .F.

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

loPubkey = createobject("CkPublicKey")

llSuccess = loPubkey.LoadBase64("MIICdgIBADA ... A9PXLk+j5A==")
if (llSuccess = .F.) then
    ? loPubkey.LastErrorText
    release loPubkey
    return
endif

loRsa = createobject("CkRsa")

llSuccess = loRsa.UsePublicKey(loPubkey)
if (llSuccess = .F.) then
    ? loRsa.LastErrorText
    release loPubkey
    release loRsa
    return
endif

loRsa.EncodingMode = "base64"

lcEncryptedStr = loRsa.EncryptStringENC("12345678",.F.)

? lcEncryptedStr


release loPubkey
release loRsa