Sample code for 30+ languages & platforms
AutoIt

Get the Certificate Used for Decryption

See more MIME Examples

Loads a CMS/PKCS #7 encrypted S/MIME message and decrypts it back to the original MIME content.

After a successful decryption, LastDecryptCert loads the certificate(s) actually used into a Cert object, indexed from zero up to NumDecryptCerts minus one.

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. Following decryption or security unwrapping, Chilkat records which certificate(s) were used. LastDecryptCert retrieves them so the application can report or verify the identity involved.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

$oMime = ObjCreate("Chilkat.Mime")
$bSuccess = $oMime.LoadMimeFile("qa_data/encrypted.eml")
If ($bSuccess = False) Then
    ConsoleWrite($oMime.LastErrorText & @CRLF)
    Exit
EndIf

;  Configure a decryption source and decrypt.
Local $sPfxPassword = "myPfxPassword"
$bSuccess = $oMime.AddPfxSourceFile("qa_data/recipient.pfx",$sPfxPassword)
If ($bSuccess = False) Then
    ConsoleWrite($oMime.LastErrorText & @CRLF)
    Exit
EndIf

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

;  After a successful decryption, load the certificate(s) that were used.  The 1st argument is the
;  zero-based index and the 2nd is a Cert that receives the certificate.
Local $iN = $oMime.NumDecryptCerts
$oCert = ObjCreate("Chilkat.Cert")
Local $i
For $i = 0 To $iN - 1
    $bSuccess = $oMime.LastDecryptCert($i,$oCert)
    If ($bSuccess = False) Then
        ConsoleWrite($oMime.LastErrorText & @CRLF)
        Exit
    EndIf

    ConsoleWrite("Decrypted with: " & $oCert.SubjectCN & @CRLF)
Next