Sample code for 30+ languages & platforms
AutoIt

Add S/MIME Signature using PFX

See more MIME Examples

Add a digital signature to a MIME message using the certificate + private key from a PFX file.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oMime = ObjCreate("Chilkat.Mime")

; Load a PFX file into a certificate object.
$oCert = ObjCreate("Chilkat.Cert")
Local $sPfxFilepath = "pfxFiles/something.pfx"
Local $sPfxPassword = "secret"
$bSuccess = $oCert.LoadPfxFile($sPfxFilepath,$sPfxPassword)
If ($bSuccess = False) Then
    ConsoleWrite($oCert.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oMime.SetBodyFromPlainText("This is the plain-text MIME body.")

$oMime.Charset = "utf-8"
$oMime.Encoding = "quoted-printable"

; Sign the MIME (adds a PKCS7 detached signature)
$bSuccess = $oMime.AddDetachedSignature($oCert)
If ($bSuccess = False) Then
    ConsoleWrite($oMime.LastErrorText & @CRLF)
    Exit
EndIf

; Save the S/MIME to a file.
$bSuccess = $oMime.SaveMime("/temp/signedMime.txt")
If ($bSuccess = False) Then
    ConsoleWrite($oMime.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("success!" & @CRLF)