Sample code for 30+ languages & platforms
PowerBuilder

Decrypt a .p7m File (using a PFX)

See more Encryption Examples

_LANGUAGE_ sample code showing how to decrypt a .p7m using a .p12 / .pfx certificate w/ private key.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Crypt
string ls_PfxPath
string ls_PfxPassword
string ls_InPath
string ls_OutPath

li_Success = 0

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

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

// Use a digital certificate and private key from a PFX file (.pfx or .p12).
ls_PfxPath = "myCertAndKey.pfx"
ls_PfxPassword = "test123"

li_Success = loo_Crypt.AddPfxSourceFile(ls_PfxPath,ls_PfxPassword)
if li_Success <> 1 then
    Write-Debug loo_Crypt.LastErrorText
    destroy loo_Crypt
    return
end if

// Set the  outPath to whatever is appropriate.
// If you are decrypting a PDF, your output might be "out.pdf"...
ls_InPath = "smime.p7m"
ls_OutPath = "original.txt"

// Indicate that we're doing public key decryption (i.e. PKCS7)
loo_Crypt.CryptAlgorithm = "pki"

li_Success = loo_Crypt.CkDecryptFile(ls_InPath,ls_OutPath)
if li_Success = 0 then
    Write-Debug loo_Crypt.LastErrorText
    destroy loo_Crypt
    return
end if

Write-Debug "Success."


destroy loo_Crypt