Sample code for 30+ languages & platforms
PowerBuilder

Write a PFX to a File

See more PFX/P12 Examples

Demonstrates Pfx.ToFile, which serializes the current PFX contents and writes the resulting PKCS#12 data to a file, using the supplied output password.

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 .pfx and .p12 extensions both denote PKCS#12 files. The output password protects the private keys in the resulting file.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Pfx
string ls_Password
string ls_OutputPassword

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 and write the PKCS#12 data to a file, using the given output password.
//  The output password should come from a secure source rather than being hard-coded.
ls_OutputPassword = "myOutputPassword"
li_Success = loo_Pfx.ToFile(ls_OutputPassword,"qa_output/identity.pfx")
if li_Success = 0 then
    Write-Debug loo_Pfx.LastErrorText
    destroy loo_Pfx
    return
end if

Write-Debug "PFX written to file."


destroy loo_Pfx