Xbase++ Requires Chilkat v11.0.0+
Xbase++
Load PEM Public/Private Key into RSA Object
See more RSA Examples
Demonstrates how to load a PEM key into the Chilkat RSA object.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oRsa
LOCAL cPublicKeyPem
LOCAL oPubkey
LOCAL cPrivateKeyPem
LOCAL oPrivkey
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oRsa := CreateObject("Chilkat.Rsa")
// First demonstrate importing a PEM public key:
cPublicKeyPem := "PEM public-key data goes here"
oPubkey := CreateObject("Chilkat.PublicKey")
nSuccess := oPubkey:LoadFromString(cPublicKeyPem)
IF (nSuccess == 0)
? oPubkey:LastErrorText
oRsa:destroy()
oPubkey:destroy()
RETURN
ENDIF
nSuccess := oRsa:UsePublicKey(oPubkey)
IF (nSuccess == 0)
? oRsa:LastErrorText
oRsa:destroy()
oPubkey:destroy()
RETURN
ENDIF
// Demonstrate importing a PEM private key:
cPrivateKeyPem := "PEM private-key data goes here"
oPrivkey := CreateObject("Chilkat.PrivateKey")
// If the private key PEM is protected with a password, then
// call LoadEncryptedPem. Otherwise call LoadPem.
nSuccess := oPrivkey:LoadPem(cPrivateKeyPem)
IF (nSuccess == 0)
? oPrivkey:LastErrorText
oRsa:destroy()
oPubkey:destroy()
oPrivkey:destroy()
RETURN
ENDIF
nSuccess := oRsa:UsePrivateKey(oPrivkey)
IF (nSuccess == 0)
? oRsa:LastErrorText
oRsa:destroy()
oPubkey:destroy()
oPrivkey:destroy()
RETURN
ENDIF
? "OK!"
oRsa:destroy()
oPubkey:destroy()
oPrivkey:destroy()