Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v11.8.0+

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 PEM file.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Mime
string ls_PemPassword
oleobject loo_Pem

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 AddPemSource method may be called one or more times
//  (one per Pem object) to add sources from which the MIME component will
//  search for certificates and private keys when decrypting.
//  Here the certificate and its private key are loaded from a PEM file.
//  The 2nd argument of LoadPemFile is the password of the private key.
ls_PemPassword = "myPassword"
loo_Pem = create oleobject
li_rc = loo_Pem.ConnectToNewObject("Chilkat.Pem")

li_Success = loo_Pem.LoadPemFile("myCertAndPrivateKey.pem",ls_PemPassword)
if li_Success = 0 then
    Write-Debug loo_Pem.LastErrorText
    destroy loo_Mime
    destroy loo_Pem
    return
end if

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

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

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


destroy loo_Mime
destroy loo_Pem