Sample code for 30+ languages & platforms
AutoIt

CAdES BES Detached Signature

See more Encryption Examples

Demonstrates how to create a CAdES BES detached signature file (.p7s).

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

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

$oCrypt = ObjCreate("Chilkat.Crypt2")

; Use a digital certificate and private key from a PFX file (.pfx or .p12).
Local $sPfxPath = "/Users/chilkat/testData/pfx/acme.pfx"
Local $sPfxPassword = "test123"

$oCert = ObjCreate("Chilkat.Cert")
$bSuccess = $oCert.LoadPfxFile($sPfxPath,$sPfxPassword)
If ($bSuccess <> True) Then
    ConsoleWrite($oCert.LastErrorText & @CRLF)
    Exit
EndIf

; Tell the crypt component to use this cert.
$bSuccess = $oCrypt.SetSigningCert($oCert)
If ($bSuccess <> True) Then
    ConsoleWrite($oCrypt.LastErrorText & @CRLF)
    Exit
EndIf

; The CadesEnabled property applies to all methods that create PKCS7 signatures. 
; To create a CAdES-BES signature, set this property equal to true. 
$oCrypt.CadesEnabled = True

; We can sign any type of file, creating a .p7s as output:
Local $sInFile = "/Users/chilkat/testData/pdf/sample.pdf"
Local $sigFile = "/Users/chilkat/testData/p7s/sample.p7s"

; Create the detached CAdES-BES signature:
$bSuccess = $oCrypt.CreateP7S($sInFile,$sigFile)
If ($bSuccess = False) Then
    ConsoleWrite($oCrypt.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oCrypt.VerifyP7S($sInFile,$sigFile)
If ($bSuccess = False) Then
    ConsoleWrite($oCrypt.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite("Success!" & @CRLF)