PowerBuilder
PowerBuilder
Iterate Keys and Certs in PEM
See more PEM Examples
Demonstrates how to access each of the private keys and certs contained within a PEM.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Pem
string ls_Password
string ls_PemContent
integer li_NumPrivateKeys
integer i
oleobject loo_PrivKey
oleobject loo_Cert
integer li_NumCerts
li_Success = 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Pem = create oleobject
li_rc = loo_Pem.ConnectToNewObject("Chilkat.Pem")
if li_rc < 0 then
destroy loo_Pem
MessageBox("Error","Connecting to COM object failed")
return
end if
// Load the PEM from a file.
// If the PEM is encrypted, provide a password. Otherwise pass an empty string for the password.
ls_Password = "myPassword"
li_Success = loo_Pem.LoadPemFile("../myPemFiles/myPem.pem",ls_Password)
if li_Success = 0 then
Write-Debug loo_Pem.LastErrorText
destroy loo_Pem
return
end if
// Note: If the app already has the PEM pre-loaded in a string variable, then load it
// by calling LoadPem instead.
ls_PemContent = "... the PEM contents ..."
li_Success = loo_Pem.LoadPem(ls_PemContent,ls_Password)
// Check for success as before..
// Iterate over the private keys.
li_NumPrivateKeys = loo_Pem.NumPrivateKeys
i = 0
loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey")
do while i < li_NumPrivateKeys
loo_Pem.PrivateKeyAt(i,loo_PrivKey)
Write-Debug "Private Key " + string(i) + " is " + string(loo_PrivKey.BitLength) + " in length"
i = i + 1
loop
// Iterate over the certificates.
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
li_NumCerts = loo_Pem.NumCerts
i = 0
do while i < li_NumCerts
loo_Pem.CertAt(i,loo_Cert)
Write-Debug "Certificate " + string(i) + " : " + loo_Cert.SubjectDN
i = i + 1
loop
destroy loo_Pem
destroy loo_PrivKey
destroy loo_Cert