AutoIt
AutoIt
Set Cert and Private Key for S/MIME Decryption
See more IMAP Examples
Demonstrates the Chilkat Imap.SetDecryptCert2 method, which specifies a certificate together with a separately supplied private key for decrypting S/MIME messages. The first argument is the Cert and the second is the PrivateKey. This example loads the certificate and key from separate files.
Note: The certificate path is relative to the application's current working directory. Supply the path to your own certificate file.
Background: Sometimes the certificate (the public part) and the private key are stored separately — a
.cer alongside a PEM key file, for instance. This method pairs them explicitly, whereas SetDecryptCert expects a single Cert that already provides its private key. After the pairing, subsequently downloaded S/MIME messages are decrypted automatically.Chilkat AutoIt Downloads
Local $bSuccess = False
; Demonstrates the Imap.SetDecryptCert2 method, which specifies a certificate together with a
; separately supplied private key for decrypting S/MIME messages. The 1st argument is the
; Cert and the 2nd is the PrivateKey.
$oImap = ObjCreate("Chilkat.Imap")
$oImap.Ssl = True
$oImap.Port = 993
$bSuccess = $oImap.Connect("imap.example.com")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oImap.Login("user@example.com","myPassword")
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
; Load the certificate and its private key from separate files.
$oCert = ObjCreate("Chilkat.Cert")
$bSuccess = $oCert.LoadFromFile("qa_data/smime.cer")
If ($bSuccess = False) Then
ConsoleWrite($oCert.LastErrorText & @CRLF)
Exit
EndIf
$oPrivKey = ObjCreate("Chilkat.PrivateKey")
$bSuccess = $oPrivKey.LoadPemFile("qa_data/smime_privkey.pem")
If ($bSuccess = False) Then
ConsoleWrite($oPrivKey.LastErrorText & @CRLF)
Exit
EndIf
; Use the cert and key to automatically decrypt subsequently downloaded S/MIME messages.
$bSuccess = $oImap.SetDecryptCert2($oCert,$oPrivKey)
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf
$bSuccess = $oImap.Disconnect()
If ($bSuccess = False) Then
ConsoleWrite($oImap.LastErrorText & @CRLF)
Exit
EndIf