PowerBuilder
PowerBuilder
Read a PFX Safe-Bag Attribute
See more PFX/P12 Examples
Demonstrates Pfx.GetSafeBagAttr, which reads a recognized safe-bag attribute from a private key or certificate inside the 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.
Background. A safe-bag attribute is metadata attached to an item inside a PKCS#12/PFX container; it does not change the certificate or private-key material. Recognized attributes include friendlyName, keyContainerName, keyName, and localKeyId.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Pfx
string ls_Password
integer li_BForPrivateKey
string ls_FriendlyName
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
// Read a recognized safe-bag attribute from an item inside the PFX. The 1st argument is 1 for a
// private key or 0 for a certificate, and the 2nd is the zero-based index within that
// collection.
li_BForPrivateKey = 1
ls_FriendlyName = loo_Pfx.GetSafeBagAttr(li_BForPrivateKey,0,"friendlyName")
if loo_Pfx.LastMethodSuccess = 0 then
Write-Debug loo_Pfx.LastErrorText
destroy loo_Pfx
return
end if
Write-Debug "friendlyName: " + ls_FriendlyName
destroy loo_Pfx