Sample code for 30+ languages & platforms
PowerBuilder

Add a PFX Source from BinData

See more Email Object Examples

Demonstrates the Chilkat Email.AddPfxSourceBd method, which adds PFX data held in a BinData object to the list of certificate and private-key sources used during decryption or signing. The second argument is the PFX password. Call it before obtaining the encrypted email so Chilkat can decrypt it automatically. This example loads a PFX into a BinData, adds it, and then loads an encrypted email.

Background: This is the in-memory (BinData) counterpart to AddPfxSourceFile. It is the right choice when the PFX bytes come from somewhere other than a file — a database, a secrets manager, or an HTTP download — letting you supply the certificate and private key without first writing them to disk (which is preferable for sensitive key material).

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_BdPfx

li_Success = 0

//  Demonstrates the AddPfxSourceBd method, which adds PFX data (held in a BinData) to the
//  list of certificate and private-key sources used during decryption or signing.  The
//  second argument is the PFX password.  Call it before obtaining the encrypted email.

loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")
if li_rc < 0 then
    destroy loo_Email
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Load PFX data into a BinData object.
loo_BdPfx = create oleobject
li_rc = loo_BdPfx.ConnectToNewObject("Chilkat.BinData")

li_Success = loo_BdPfx.LoadFile("qa_data/certs/decryption.pfx")
if li_Success = 0 then
    Write-Debug loo_BdPfx.LastErrorText
    destroy loo_Email
    destroy loo_BdPfx
    return
end if

//  Add the PFX as a source of the certificate + private key.
li_Success = loo_Email.AddPfxSourceBd(loo_BdPfx,"pfx_password")
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    destroy loo_BdPfx
    return
end if

//  Load an encrypted email; Chilkat decrypts it using the PFX source.
li_Success = loo_Email.LoadEml("qa_data/eml/encrypted.eml")
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    destroy loo_BdPfx
    return
end if

Write-Debug "Decrypted = " + string(loo_Email.Decrypted)

//  Note: Paths such as "qa_data/..." are relative local filesystem paths,
//  relative to the current working directory of the running application.


destroy loo_Email
destroy loo_BdPfx