PowerBuilder
PowerBuilder
Load PKCS12 / PFX and Access Contents
See more PFX/P12 Examples
Loads a PKCS12 / PFX file and iterates over the contents which include private keys and certificates.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Pfx
integer li_NumPrivateKeys
oleobject loo_PrivKey
integer i
oleobject loo_Cert
integer li_NumCerts
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
// Load the PKCS12 from a file
li_Success = loo_Pfx.LoadPfxFile("/someDir/my.p12","pfxFilePassword")
if li_Success = 0 then
Write-Debug loo_Pfx.LastErrorText
destroy loo_Pfx
return
end if
li_NumPrivateKeys = loo_Pfx.NumPrivateKeys
loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey")
Write-Debug "Private Keys:"
i = 0
do while i < li_NumPrivateKeys
loo_Pfx.PrivateKeyAt(i,loo_PrivKey)
// Do something with the private key ...
i = i + 1
loop
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
li_NumCerts = loo_Pfx.NumCerts
Write-Debug "Certs:"
i = 0
do while i < li_NumCerts
loo_Pfx.CertAt(i,loo_Cert)
Write-Debug loo_Cert.SubjectDN
// If the certificate has a private key (one of the private keys within the PFX)
// then it can also be obtained via the certificate object:
if loo_Cert.HasPrivateKey() = 1 then
Write-Debug "Has private key!"
li_Success = loo_Cert.GetPrivateKey(loo_PrivKey)
// ...
end if
i = i + 1
loop
destroy loo_Pfx
destroy loo_PrivKey
destroy loo_Cert