Sample code for 30+ languages & platforms
AutoIt

Create PKCS7 Signed File (.p7m)

See more Encryption Examples

Demonstrates how to sign a file to create a .p7m that contains both the file contents and the signature.

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.

$oCrypt = ObjCreate("Chilkat.Crypt2")

$oCertStore = ObjCreate("Chilkat.CertStore")

; Load a PFX file into a certificate store object.
$bSuccess = $oCertStore.LoadPfxFile("myPfx.pfx","pfxPassword")
If ($bSuccess <> True) Then
    ConsoleWrite($oCertStore.LastErrorText & @CRLF)
    Exit
EndIf

; Get the certificate by subject common name.
; This should be the cert within the PFX that also
; has a private key (also stored within the PFX).
$oJsonCN = ObjCreate("Chilkat.JsonObject")
$oJsonCN.UpdateString("CN","myCert")
$oCert = ObjCreate("Chilkat.Cert")
$bSuccess = $oCertStore.FindCert($oJsonCN,$oCert)
If ($bSuccess = False) Then
    ConsoleWrite($oCertStore.LastErrorText & @CRLF)
    Exit
EndIf

; Tell the crypt object to use the certificate for signing:
$bSuccess = $oCrypt.SetSigningCert($oCert)

; Sign a file, producing a .p7m as output.
; The input file is unchanged, the test.p7m contains the 
; contents of the input file and the signature.
Local $sInFile = "test.txt"
Local $sOutFile = "testp7m"
$bSuccess = $oCrypt.CreateP7M($sInFile,$sOutFile)
If ($bSuccess <> True) Then
    ConsoleWrite($oCrypt.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Success!" & @CRLF)