AutoIt
AutoIt
Set the Decryption Certificate and Private Key
See more POP3 Examples
Demonstrates the Chilkat MailMan.SetDecryptCert2 method, which explicitly specifies both the certificate and its associated private key, as separate objects, to use when decrypting S/MIME encrypted email. This example loads a .cer certificate and a PEM private key, registers both, and fetches a message Chilkat can decrypt.
Background: Credentials are not always packaged together. When the certificate is a standalone
.cer and the private key is a separate PEM (or other) file, SetDecryptCert2 takes the two objects individually. It is the two-object counterpart to SetDecryptCert, which expects a single certificate that already carries its private key (such as one loaded from a PFX).Chilkat AutoIt Downloads
Local $bSuccess = False
; Demonstrates the MailMan.SetDecryptCert2 method, which explicitly specifies both the
; certificate and its associated private key (as separate objects) to use when decrypting
; S/MIME encrypted email.
$oMailman = ObjCreate("Chilkat.MailMan")
; Configure the POP3 server connection.
$oMailman.MailHost = "pop.example.com"
$oMailman.MailPort = 995
$oMailman.PopSsl = True
$oMailman.PopUsername = "user@example.com"
$oMailman.PopPassword = "myPassword"
; Load the certificate (public) and the matching private key from separate files.
$oCert = ObjCreate("Chilkat.Cert")
$bSuccess = $oCert.LoadFromFile("qa_data/certs/recipient.cer")
If ($bSuccess = False) Then
ConsoleWrite($oCert.LastErrorText & @CRLF)
Exit
EndIf
$oPrivKey = ObjCreate("Chilkat.PrivateKey")
$bSuccess = $oPrivKey.LoadPemFile("qa_data/certs/recipient_privkey.pem")
If ($bSuccess = False) Then
ConsoleWrite($oPrivKey.LastErrorText & @CRLF)
Exit
EndIf
; Specify the certificate and private key to use when decrypting downloaded email.
$bSuccess = $oMailman.SetDecryptCert2($oCert,$oPrivKey)
If ($bSuccess = False) Then
ConsoleWrite($oMailman.LastErrorText & @CRLF)
Exit
EndIf
; Fetch a message; if it is encrypted, Chilkat decrypts it using the certificate and key.
$oEmail = ObjCreate("Chilkat.Email")
$bSuccess = $oMailman.FetchOne(False,0,1,$oEmail)
If ($bSuccess = False) Then
ConsoleWrite($oMailman.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Decrypted = " & $oEmail.Decrypted & @CRLF)
; Note: Paths such as "qa_data/..." are relative local filesystem paths,
; relative to the current working directory of the running application.
; Note: Explicitly connecting/authenticating is optional. Chilkat MailMan automatically
; connects and authenticates -- using the property settings above -- whenever a server
; operation requires it. Calling the explicit connect/authenticate methods can still be
; helpful to determine whether a failure occurs while connecting or while authenticating.