Sample code for 30+ languages & platforms
PowerBuilder

PKCS7 Decrypt MIME

See more MIME Examples

Loads a PKCS7 encrypted MIME file and decrypts. The cert and private key used for decryption is loaded from a PFX file.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mime
string ls_PfxPassword

li_Success = 0

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

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

// Load the MIME
li_Success = loo_Mime.LoadMimeFile("encryptedMime.txt")
if li_Success = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    return
end if

// The AddPfxSourceFile and/or AddPfxSourceData
// methods may be called one or more times (one per PFX)
// to add sources from which the MIME component will
// search for certificates and private keys when decrypting.
ls_PfxPassword = "myPassword"
li_Success = loo_Mime.AddPfxSourceFile("myCertAndPrivateKey.pfx",ls_PfxPassword)
if li_Success = 0 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    return
end if

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

// Display the decrypted MIME:
Write-Debug loo_Mime.GetMime()


destroy loo_Mime