![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) Sign JSON to Create CAdES P7S BytesDemonstrates how to sign JSON using a certificate + private key from a .p12/.pfx to create a CAdES P7S byte array.
; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. $oCrypt = ObjCreate("Chilkat_9_5_0.Crypt2") $oCert = ObjCreate("Chilkat_9_5_0.Cert") Local $bSuccess = $oCert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123") 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 $oCrypt.HashAlgorithm = "sha256" $oJsonSigningAttrs = ObjCreate("Chilkat_9_5_0.JsonObject") $oJsonSigningAttrs.UpdateInt("contentType",1) $oJsonSigningAttrs.UpdateInt("signingTime",1) $oJsonSigningAttrs.UpdateInt("messageDigest",1) $oJsonSigningAttrs.UpdateInt("signingCertificateV2",1) $oCrypt.SigningAttributes = $oJsonSigningAttrs.Emit() ; By default, all the certs in the chain of authentication are included in the signature. ; If desired, we can choose to only include the signing certificate: $oCrypt.IncludeCertChain = False ; Create the CAdES-BES attached signature, which contains the original data. $oCrypt.Charset = "utf-8" Local $oCadesP7s $oCadesP7s = $oCrypt.OpaqueSignString("{ ""abc"": 123}") If ($oCrypt.LastMethodSuccess = False) Then ConsoleWrite($oCrypt.LastErrorText & @CRLF) Exit EndIf ; Verify the signature and extract the original JSON: Local $sOriginalJson = $oCrypt.OpaqueVerifyString($oCadesP7s) If ($oCrypt.LastMethodSuccess = False) Then ConsoleWrite($oCrypt.LastErrorText & @CRLF) Exit EndIf ConsoleWrite("Original JSON: " & $sOriginalJson & @CRLF) ConsoleWrite("Success!" & @CRLF) |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.