Sample code for 30+ languages & platforms
PowerBuilder

Provide a Certificate Vault to an Email

See more Email Object Examples

Demonstrates the Chilkat Email.UseCertVault method, which adds an XML certificate vault to the email's internal certificate and private-key lookup sources for encryption, decryption, signing, and verification. This example builds a vault from a PFX and attaches it to the email.

Background: A certificate vault is a portable, in-memory store of certificates and private keys. Instead of wiring up each certificate individually for every operation, you load your credentials into one XmlCertVault and hand it to the email; Chilkat then draws on it automatically whenever it needs a key — to decrypt an incoming message, sign an outgoing one, or verify a signature. This is especially convenient on platforms without an OS certificate store.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Email
oleobject loo_Vault

li_Success = 0

//  Demonstrates the UseCertVault method, which adds an XML certificate vault to the email's
//  internal certificate and private-key lookup sources for encryption, decryption, signing,
//  and verification.

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

//  Build a certificate vault from a PFX (certificate + private key).
loo_Vault = create oleobject
li_rc = loo_Vault.ConnectToNewObject("Chilkat.XmlCertVault")

li_Success = loo_Vault.AddPfxFile("qa_data/certs/certs.pfx","pfx_password")
if li_Success = 0 then
    Write-Debug loo_Vault.LastErrorText
    destroy loo_Email
    destroy loo_Vault
    return
end if

//  Make the vault available to the email object for crypto operations.
li_Success = loo_Email.UseCertVault(loo_Vault)
if li_Success = 0 then
    Write-Debug loo_Email.LastErrorText
    destroy loo_Email
    destroy loo_Vault
    return
end if

Write-Debug "Certificate vault attached to the email."

//  Note: The path "qa_data/certs/certs.pfx" is a relative local filesystem path,
//  relative to the current working directory of the running application.


destroy loo_Email
destroy loo_Vault