Xbase++
Xbase++
Add S/MIME Signature using PFX
See more MIME Examples
Add a digital signature to a MIME message using the certificate + private key from a PFX file.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oMime
LOCAL oCert
LOCAL cPfxFilepath
LOCAL cPfxPassword
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oMime := CreateObject("Chilkat.Mime")
// Load a PFX file into a certificate object.
oCert := CreateObject("Chilkat.Cert")
cPfxFilepath := "pfxFiles/something.pfx"
cPfxPassword := "secret"
nSuccess := oCert:LoadPfxFile(cPfxFilepath, cPfxPassword)
IF (nSuccess == 0)
? oCert:LastErrorText
oMime:destroy()
oCert:destroy()
RETURN
ENDIF
nSuccess := oMime:SetBodyFromPlainText("This is the plain-text MIME body.")
oMime:Charset := "utf-8"
oMime:Encoding := "quoted-printable"
// Sign the MIME (adds a PKCS7 detached signature)
nSuccess := oMime:AddDetachedSignature(oCert)
IF (nSuccess == 0)
? oMime:LastErrorText
oMime:destroy()
oCert:destroy()
RETURN
ENDIF
// Save the S/MIME to a file.
nSuccess := oMime:SaveMime("/temp/signedMime.txt")
IF (nSuccess == 0)
? oMime:LastErrorText
oMime:destroy()
oCert:destroy()
RETURN
ENDIF
? "success!"
oMime:destroy()
oCert:destroy()