Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

RSA Import Public Key from Certificate PEM

See more RSA Examples

Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oCert
LOCAL oPubKey
LOCAL oRsa
LOCAL cEncryptedStr

nSuccess := 0

oCert := CreateObject("Chilkat.Cert")

nSuccess := oCert:LoadFromFile("qa_data/pem/mf_public_rsa.pem")
IF (nSuccess == 0)
    ? oCert:LastErrorText
    oCert:destroy()
    RETURN
ENDIF

oPubKey := CreateObject("Chilkat.PublicKey")
oCert:GetPublicKey(oPubKey)

oRsa := CreateObject("Chilkat.Rsa")
oRsa:UsePublicKey(oPubKey)

oRsa:EncodingMode := "base64"
cEncryptedStr := oRsa:EncryptStringENC("hello", 0)
? "encrypted string = " + cEncryptedStr

oCert:destroy()
oPubKey:destroy()
oRsa:destroy()