Sample code for 30+ languages & platforms
Xojo Plugin

Load Identities from PEM Text

See more PFX/P12 Examples

Demonstrates Pfx.LoadPem, which loads one or more certificate/private-key identities from PEM-formatted text and builds the contents of the Pfx object.

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.

Background. The password decrypts any encrypted private keys in the PEM. This builds a PFX in memory from PEM material, which can then be serialized to PKCS#12.

Chilkat Xojo Plugin Downloads

Xojo Plugin
Dim success As Boolean
success = False

Dim pfx As New Chilkat.Pfx

//  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.
//  Load the PEM text (certificates and private keys) into a string.
Dim sbPem As New Chilkat.StringBuilder
Dim bLoaded As Boolean
bLoaded = sbPem.LoadFile("qa_data/identity.pem")
If (bLoaded <> True) Then
    System.DebugLog("Failed to load the PEM file.")
    Return
End If

Dim pemText As String
pemText = sbPem.GetAsString()
If (sbPem.LastMethodSuccess = False) Then
    System.DebugLog(sbPem.LastErrorText)
    Return
End If

//  The password decrypts any encrypted private keys in the PEM (use an empty string if none are
//  encrypted).  A password should come from a secure source rather than being hard-coded.
Dim password As String
password = "myPemPassword"
success = pfx.LoadPem(pemText,password)
If (success = False) Then
    System.DebugLog(pfx.LastErrorText)
    Return
End If

System.DebugLog("Loaded " + Str(pfx.NumPrivateKeys) + " private key(s).")