Sample code for 30+ languages & platforms
AutoIt

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 AutoIt Downloads

AutoIt
Local $bSuccess = False

$oMime = ObjCreate("Chilkat.Mime")
$bSuccess = $oMime.SetBodyFromPlainText("This message will be encrypted.")
If ($bSuccess = False) Then
    ConsoleWrite($oMime.LastErrorText & @CRLF)
    Exit
EndIf

;  AddEncryptCert adds one recipient certificate to the list used by EncryptN.  Call it once per
;  recipient.
$oCert = ObjCreate("Chilkat.Cert")
$bSuccess = $oCert.LoadFromFile("qa_data/recipient.cer")
If ($bSuccess = False) Then
    ConsoleWrite($oCert.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oMime.AddEncryptCert($oCert)
If ($bSuccess = False) Then
    ConsoleWrite($oMime.LastErrorText & @CRLF)
    Exit
EndIf

;  EncryptN then encrypts for all certificates added.
$bSuccess = $oMime.EncryptN()
If ($bSuccess = False) Then
    ConsoleWrite($oMime.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Encrypted for the added recipient(s)." & @CRLF)