Sample code for 30+ languages & platforms
PowerBuilder

Serialize a PFX to BinData

See more PFX/P12 Examples

Demonstrates Pfx.ToBd, which serializes the current PFX contents as PKCS#12 data into a BinData object, using the supplied output password.

Background. This is the in-memory equivalent of ToFile, producing the PKCS#12 bytes for further processing or transport.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Pfx
string ls_Password
string ls_OutputPassword
oleobject loo_Bd

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

//  Serialize the PFX contents as PKCS#12 data into a BinData, using the given output password.
ls_OutputPassword = "myOutputPassword"
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")

li_Success = loo_Pfx.ToBd(ls_OutputPassword,loo_Bd)
if li_Success = 0 then
    Write-Debug loo_Pfx.LastErrorText
    destroy loo_Pfx
    destroy loo_Bd
    return
end if

Write-Debug "Serialized " + string(loo_Bd.NumBytes) + " bytes of PKCS#12 data."


destroy loo_Pfx
destroy loo_Bd