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
(MFC) Sign PDF for ICP-BrasilSee more PDF Signatures ExamplesSign a PDF to create a signed PDF compliant with the ICP-Brasil Digital Signature Standard Conformity Checker. (Verificador de Conformidade do PadrĂ£o de Assinatura Digital ICP-Brasil) Note: This example requires Chilkat v9.5.0.87 or greater. For more information, see https://verificador.iti.gov.br/verifier-2.6.2/
#include <CkPdf.h> #include <CkJsonObject.h> #include <CkCert.h> void ChilkatSample(void) { CkString strOut; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // The signed PDF produced by this example should be verifiable at https://verificador.iti.gov.br/verifier-2.6.2/ CkPdf pdf; // Load a PDF to be signed. // The "hello.pdf" is available at https://chilkatsoft.com/hello.pdf bool success = pdf.LoadFile("qa_data/pdf/hello.pdf"); if (success == false) { strOut.append(pdf.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } CkJsonObject json; // Define the appearance and location of the signature. json.UpdateInt("page",1); json.UpdateString("appearance.y","bottom"); json.UpdateString("appearance.x","middle"); json.UpdateString("appearance.fontScale","9.0"); json.UpdateString("appearance.text[0]","Digitally signed by: cert_cn"); json.UpdateString("appearance.text[1]","current_dt"); json.UpdateString("appearance.image","document-accepted"); json.UpdateString("appearance.imagePlacement","left"); json.UpdateString("appearance.imageOpacity","100"); // Add the CMS options required for ICP-Brasil json.UpdateInt("contentType",1); json.UpdateInt("messageDigest",1); json.UpdateInt("signingCertificateV2",1); json.UpdateString("policyId.id","2.16.76.1.7.1.1.2.3"); json.UpdateString("policyId.hash","sW6Iu/dzIqZ5lbeQeHeO09DqfIhYe29tUYtxXo92o9U="); json.UpdateString("policyId.uri","http://politicas.icpbrasil.gov.br/PA_AD_RB_v2_3.der"); json.UpdateString("policyId.hashAlg","SHA256"); // Load the signing certificate. (Use your own certificate.) // Note: If loading from a smart card, call LoadFromSmartcard instead, and make sure to use Chilkat v9.5.0.88 or later. CkCert cert; success = cert.LoadPfxFile("qa_data/pfx/myPdfSigningCert.pfx","pfx_password"); if (success == false) { strOut.append(cert.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Tell the pdf object to use the certificate for signing. success = pdf.SetSigningCert(cert); if (success == false) { strOut.append(pdf.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } success = pdf.SignPdf(json,"qa_output/hello_signed.pdf"); if (success == false) { strOut.append(pdf.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } strOut.append("The PDF has been successfully cryptographically signed."); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.