Sample code for 30+ languages & platforms
PowerBuilder

Add a Recipient Certificate for S/MIME Encryption

See more MIME Examples

Demonstrates AddEncryptCert, which adds one recipient certificate to the list used by EncryptN. Call it once for each intended recipient, then call EncryptN to encrypt for all of them.

The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background. AddEncryptCert builds up the recipient list used by EncryptN. Only the public key of each certificate is required for encryption.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mime
oleobject loo_Cert

li_Success = 0

loo_Mime = create oleobject
li_rc = loo_Mime.ConnectToNewObject("Chilkat.Mime")
if li_rc < 0 then
    destroy loo_Mime
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Mime.SetBodyFromPlainText("This message will be encrypted.")
if li_Success = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    return
end if

//  AddEncryptCert adds one recipient certificate to the list used by EncryptN.  Call it once per
//  recipient.
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")

li_Success = loo_Cert.LoadFromFile("qa_data/recipient.cer")
if li_Success = 0 then
    Write-Debug loo_Cert.LastErrorText
    destroy loo_Mime
    destroy loo_Cert
    return
end if

li_Success = loo_Mime.AddEncryptCert(loo_Cert)
if li_Success = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    destroy loo_Cert
    return
end if

//  EncryptN then encrypts for all certificates added.
li_Success = loo_Mime.EncryptN()
if li_Success = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    destroy loo_Cert
    return
end if

Write-Debug "Encrypted for the added recipient(s)."


destroy loo_Mime
destroy loo_Cert