Sample code for 30+ languages & platforms
PowerBuilder

Load a Private Key from PEM Text

See more Private Key Examples

Demonstrates the Chilkat PrivateKey.LoadPem method, which loads a private key from PEM text. The only argument is the PEM string. It has no password argument, so it cannot load an encrypted PEM — use LoadEncryptedPem for that.

Background: PEM is the Base64 text format (delimited by -----BEGIN----- lines) that most tooling uses for keys. This method is for the plain, unencrypted case where the key material sits in the clear inside the PEM — convenient, but it means the file itself is the only thing protecting the key. When the PEM is password-protected (a BEGIN ENCRYPTED PRIVATE KEY block or a legacy encrypted header), reach for the Encrypted loader instead.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_PrivKey
string ls_PemText

li_Success = 0

//  Demonstrates the PrivateKey.LoadPem method, which loads a private key from PEM text.  The only
//  argument is the PEM string.  This method has no password argument, so it cannot load an
//  encrypted PEM -- use LoadEncryptedPem for that.

loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey")
if li_rc < 0 then
    destroy loo_PrivKey
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  The PEM text of an unencrypted private key.
ls_PemText = "-----BEGIN PRIVATE KEY-----~nMIIEvAIBADANBgkq...~n-----END PRIVATE KEY-----"

li_Success = loo_PrivKey.LoadPem(ls_PemText)
if li_Success = 0 then
    Write-Debug loo_PrivKey.LastErrorText
    destroy loo_PrivKey
    return
end if

Write-Debug "Loaded a " + loo_PrivKey.KeyType + " private key."


destroy loo_PrivKey