Xbase++
Xbase++
Extract PKCS7 from MIME and Decrypt
See more MIME Examples
Extracts the base64-encoded PKCS7 body of a MIME message to a file, and then decrypts using Chilkat Crypt2.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oMime
LOCAL oCrypt
LOCAL cInPath
LOCAL cOutPath
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oMime := CreateObject("Chilkat.Mime")
nSuccess := oMime:LoadMimeFile("c:/aaworkarea/EmailInBytes.txt")
IF (nSuccess != 1)
? oMime:LastErrorText
oMime:destroy()
RETURN
ENDIF
nSuccess := oMime:SaveBody("c:/aaworkarea/smime.p7m")
IF (nSuccess != 1)
? oMime:LastErrorText
oMime:destroy()
RETURN
ENDIF
oCrypt := CreateObject("Chilkat.Crypt2")
nSuccess := oCrypt:AddPfxSourceFile("c:/aaworkarea/my.pfx", "pfxPassword")
IF (nSuccess == 0)
? oCrypt:LastErrorText
oMime:destroy()
oCrypt:destroy()
RETURN
ENDIF
// Indicate the public-key (PKCS7) encryption/decryption should be used:
oCrypt:CryptAlgorithm := "pki"
cInPath := "c:/aaworkarea/smime.p7m"
cOutPath := "c:/aaworkarea/decrypted.dat"
nSuccess := oCrypt:CkDecryptFile(cInPath, cOutPath)
IF (nSuccess == 0)
? oCrypt:LastErrorText
oMime:destroy()
oCrypt:destroy()
RETURN
ENDIF
? "Success."
oMime:destroy()
oCrypt:destroy()