Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(Excel) Create ICP-Brasil Compliant CMS SignatureDemonstrates how to create a .p7s signature that contains a data file, which in this case is a PDF. The .p7s will be compliant with the ICP-Brazil Digital Signature Standard. The .p7s file created by this example can be verified at ICP-Brasil Online Verifier Important: This example requires Chilkat v9.5.0.83 or later. For more information, see http://www.iti.gov.br/images/repositorio/consulta-publica/encerradas/DOC-ICP-15_-_Versao_2.2_VISAO_GERAL_SOBRE_ASSIN_DIG_NA_ICP-BRASIL_xx-xx-2015.pdf
' This example requires the Chilkat API to have been previously unlocked. ' See Global Unlock Sample for sample code. ' ------------------------------------------------------------------------------------------------------ ' Note: This example creates a CMS signature (.p7s) that contains the PDF. ' It is different than signing a PDF. To sign a PDF where the resulting PDF contains the CMS signature, ' see this example: Sign PDF for ICP-Brasil ' ------------------------------------------------------------------------------------------------------ Dim crypt As Chilkat.Crypt2 Set crypt = Chilkat.NewCrypt2 ' Any type of file can be signed. It doesn't have to be a PDF. inFile = "qa_data/pdf/helloWorld.pdf" Dim bd As Chilkat.BinData Set bd = Chilkat.NewBinData success = bd.LoadFile(inFile) If (success = False) Then Debug.Print "Failed to load "; inFile Exit Sub End If ' We'll be using a certificate w/ private key stored on a smartcard for signing. Dim cert As Chilkat.Cert Set cert = Chilkat.NewCert ' If the smartcard or token requires a PIN, we can set it here to avoid the dialog... cert.SmartCardPin = "000000" success = cert.LoadFromSmartcard("") If (success <> True) Then Debug.Print cert.LastErrorText Exit Sub End If ' Tell the crypt component to use this cert. success = crypt.SetSigningCert(cert) If (success <> True) Then Debug.Print crypt.LastErrorText Exit Sub End If ' Set properties for signing... crypt.HashAlgorithm = "sha1" Dim jsonSigningAttrs As Chilkat.JsonObject Set jsonSigningAttrs = Chilkat.NewJsonObject Dim success As Boolean success = jsonSigningAttrs.UpdateInt("contentType",1) success = jsonSigningAttrs.UpdateInt("signingTime",1) success = jsonSigningAttrs.UpdateInt("messageDigest",1) crypt.SigningAttributes = jsonSigningAttrs.Emit() ' The Brazil government validator requires the ASN.1 data to be in "constructed octets" form.. crypt.UncommonOptions = "UseConstructedOctets,OmitAlgorithmIdNull" crypt.IncludeCertChain = False ' Sign. success = crypt.OpaqueSignBd(bd) If (success = False) Then Debug.Print crypt.LastErrorText Exit Sub End If ' Save to a .p7s success = bd.WriteFile("qa_output/helloWorld.pdf.p7s") Debug.Print "Success" |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.