Visual FoxPro Requires Chilkat v11.8.0+
Visual FoxPro
Decrypt an S/MIME email and verify its signature
See more Email Object Examples
Register the recipient’s certificate and private key (from a PEM file) before opening signed-encrypted.eml. This workflow expects both encryption and a signature, so it checks both layers before reading the message. Cryptographic signature validity is one input to a signer-trust decision.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loEmail
LOCAL loPem
LOCAL loSigner
lnSuccess = 0
* Assumes Chilkat is unlocked. See Global Unlock Sample.
loEmail = CreateObject('Chilkat.Email')
* The recipient's certificate and private key are in a PEM file. The 2nd argument of LoadPemFile
* is the password of the private key.
loPem = CreateObject('Chilkat.Pem')
lnSuccess = loPem.LoadPemFile("recipient.pem","RECIPIENT_PASSWORD")
IF (lnSuccess <> 1) THEN
? loPem.LastErrorText
RELEASE loEmail
RELEASE loPem
CANCEL
ENDIF
lnSuccess = loEmail.AddPemSource(loPem)
IF (lnSuccess <> 1) THEN
? loEmail.LastErrorText
RELEASE loEmail
RELEASE loPem
CANCEL
ENDIF
lnSuccess = loEmail.LoadEml("signed-encrypted.eml")
IF (lnSuccess <> 1) THEN
? loEmail.LastErrorText
RELEASE loEmail
RELEASE loPem
CANCEL
ENDIF
IF ((loEmail.ReceivedEncrypted <> 1) OR (loEmail.Decrypted <> 1)) THEN
? "Expected a successfully decrypted S/MIME envelope."
RELEASE loEmail
RELEASE loPem
CANCEL
ENDIF
IF ((loEmail.ReceivedSigned <> 1) OR (loEmail.SignaturesValid <> 1)) THEN
? "Expected a valid signature inside the envelope."
RELEASE loEmail
RELEASE loPem
CANCEL
ENDIF
* This message has one signer. Examine its certificate after verification.
loSigner = CreateObject('Chilkat.Cert')
lnSuccess = loEmail.LastSignerCert(0,loSigner)
IF (lnSuccess <> 1) THEN
? loEmail.LastErrorText
RELEASE loEmail
RELEASE loPem
RELEASE loSigner
CANCEL
ENDIF
? "Signer certificate: " + loSigner.SubjectDN
? "Recovered subject: " + loEmail.Subject
? "Recovered attachments: " + STR(loEmail.NumAttachments)
RELEASE loEmail
RELEASE loPem
RELEASE loSigner