Sample code for 30+ languages & platforms
Visual FoxPro

Add a Recipient Certificate for S/MIME Encryption

See more MIME Examples

Demonstrates AddEncryptCert, which adds one recipient certificate to the list used by EncryptN. Call it once for each intended recipient, then call EncryptN to encrypt for all of them.

The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background. AddEncryptCert builds up the recipient list used by EncryptN. Only the public key of each certificate is required for encryption.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loMime
LOCAL loCert

lnSuccess = 0

loMime = CreateObject('Chilkat.Mime')
lnSuccess = loMime.SetBodyFromPlainText("This message will be encrypted.")
IF (lnSuccess = 0) THEN
    ? loMime.LastErrorText
    RELEASE loMime
    CANCEL
ENDIF

*  AddEncryptCert adds one recipient certificate to the list used by EncryptN.  Call it once per
*  recipient.
loCert = CreateObject('Chilkat.Cert')
lnSuccess = loCert.LoadFromFile("qa_data/recipient.cer")
IF (lnSuccess = 0) THEN
    ? loCert.LastErrorText
    RELEASE loMime
    RELEASE loCert
    CANCEL
ENDIF

lnSuccess = loMime.AddEncryptCert(loCert)
IF (lnSuccess = 0) THEN
    ? loMime.LastErrorText
    RELEASE loMime
    RELEASE loCert
    CANCEL
ENDIF

*  EncryptN then encrypts for all certificates added.
lnSuccess = loMime.EncryptN()
IF (lnSuccess = 0) THEN
    ? loMime.LastErrorText
    RELEASE loMime
    RELEASE loCert
    CANCEL
ENDIF

? "Encrypted for the added recipient(s)."

RELEASE loMime
RELEASE loCert