Sample code for 30+ languages & platforms
PowerBuilder

Export Selected PFX Contents as PEM

See more PFX/P12 Examples

Demonstrates Pfx.ToPemEx, which exports selected PFX contents as PEM-formatted text with control over which parts are included and how private keys are encrypted.

Background. Private keys are written in PKCS #8 form. Supported key-encryption algorithms include aes128, aes192, aes256, and 3des; leaving the algorithm empty produces unencrypted keys.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Pfx
string ls_Password
integer li_BExtendedAttrs
integer li_BNoKeys
integer li_BNoCerts
integer li_BNoCaCerts
string ls_KeyPassword
string ls_Pem

li_Success = 0

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

//  The file path is relative to the application's current working directory.  An absolute path
//  may also be used.  Supply the path appropriate to your own environment.
//  The PFX password should come from a secure source rather than being hard-coded.
ls_Password = "myPfxPassword"
li_Success = loo_Pfx.LoadPfxFile("qa_data/identity.pfx",ls_Password)
if li_Success = 0 then
    Write-Debug loo_Pfx.LastErrorText
    destroy loo_Pfx
    return
end if

//  Export selected PFX contents as PEM-formatted text.  The boolean arguments control what is
//  included: extended attributes, and whether to omit private keys, certificates, or CA certificates.
li_BExtendedAttrs = 0
li_BNoKeys = 0
li_BNoCerts = 0
li_BNoCaCerts = 0

//  Encrypt the exported private keys.  Supported algorithms include aes128, aes192, aes256, and 3des;
//  leave the algorithm empty for unencrypted keys.  The key password should come from a secure source.
ls_KeyPassword = "myKeyPassword"
ls_Pem = loo_Pfx.ToPemEx(li_BExtendedAttrs,li_BNoKeys,li_BNoCerts,li_BNoCaCerts,"aes256",ls_KeyPassword)
if loo_Pfx.LastMethodSuccess = 0 then
    Write-Debug loo_Pfx.LastErrorText
    destroy loo_Pfx
    return
end if

Write-Debug ls_Pem


destroy loo_Pfx