diff --git a/.github/workflows/test-net-framework-samples.yml b/.github/workflows/test-net-framework-samples.yml index 9943580..10185b6 100644 --- a/.github/workflows/test-net-framework-samples.yml +++ b/.github/workflows/test-net-framework-samples.yml @@ -93,6 +93,7 @@ jobs: 'Other/StreamIO/', 'Printing/PrintPDF/', 'Printing/PrintPDFGUI/', + 'Security/AddBasicPAdESElectronicSignature/', 'Security/AddDigitalSignatureCMS/', 'Security/AddDigitalSignatureRFC3161/', 'Security/AddRegexRedaction/', diff --git a/Samples.sln b/Samples.sln index 3783c8e..db52dde 100644 --- a/Samples.sln +++ b/Samples.sln @@ -180,6 +180,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegexTextSearch", "Text\Reg EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextExtract", "Text\TextExtract\TextExtract.csproj", "{11C4A647-3DDA-41A5-855C-E14EDF1BFFDE}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddBasicPAdESElectronicSignature", "Security\AddBasicPAdESElectronicSignature\AddBasicPAdESElectronicSignature.csproj", "{C7DF1472-B78F-402E-8841-52D2CB2B4725}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddDigitalSignatureCMS", "Security\AddDigitalSignatureCMS\AddDigitalSignatureCMS.csproj", "{AB753937-DF3D-4B06-B475-D3B597D32BC5}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddDigitalSignatureRFC3161", "Security\AddDigitalSignatureRFC3161\AddDigitalSignatureRFC3161.csproj", "{74FA984E-AB89-475A-9077-9D612DE12AEC}" @@ -554,6 +556,10 @@ Global {74FA984E-AB89-475A-9077-9D612DE12AEC}.Debug|x64.Build.0 = Debug|x64 {74FA984E-AB89-475A-9077-9D612DE12AEC}.Release|x64.ActiveCfg = Release|x64 {74FA984E-AB89-475A-9077-9D612DE12AEC}.Release|x64.Build.0 = Release|x64 + {C7DF1472-B78F-402E-8841-52D2CB2B4725}.Debug|x64.ActiveCfg = Debug|x64 + {C7DF1472-B78F-402E-8841-52D2CB2B4725}.Debug|x64.Build.0 = Debug|x64 + {C7DF1472-B78F-402E-8841-52D2CB2B4725}.Release|x64.ActiveCfg = Release|x64 + {C7DF1472-B78F-402E-8841-52D2CB2B4725}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Security/AddBasicPAdESElectronicSignature/AddBasicPAdESElectronicSignature.cs b/Security/AddBasicPAdESElectronicSignature/AddBasicPAdESElectronicSignature.cs new file mode 100644 index 0000000..47979f9 --- /dev/null +++ b/Security/AddBasicPAdESElectronicSignature/AddBasicPAdESElectronicSignature.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Datalogics.PDFL; + +/* + * + * This sample program demonstrates the use of AddDigitalSignature for PAdES + * (PDF Advanced Electronic Signatures) baseline signature type without a + * signature policy. PAdES signatures conform to the ETSI standard and use + * the ETSI.CAdES.detached SubFilter. + * + * Copyright (c) 2026, Datalogics, Inc. All rights reserved. + * + */ +namespace AddBasicPAdESElectronicSignature +{ + class AddBasicPAdESElectronicSignature + { + static void Main(string[] args) + { + Console.WriteLine("AddBasicPAdESElectronicSignature Sample:"); + + using (new Library()) + { + Console.WriteLine("Initialized the library."); + + String sInput = Library.ResourceDirectory + "Sample_Input/SixPages.pdf"; + String sLogo = Library.ResourceDirectory + "Sample_Input/ducky_alpha.tif"; + String sOutput = "PAdESBaselineSignature-out.pdf"; + + String sPEMCert = Library.ResourceDirectory + "Sample_Input/Credentials/PEM/ecSecP521r1Cert.pem"; + String sPEMKey = Library.ResourceDirectory + "Sample_Input/Credentials/PEM/ecSecP521r1Key.pem"; + + if (args.Length > 0) + sInput = args[0]; + + if (args.Length > 1) + sOutput = args[1]; + + if (args.Length > 2) + sLogo = args[2]; + + Console.WriteLine("Input file: " + sInput); + Console.WriteLine("Writing to output: " + sOutput); + + using (Document doc = new Document(sInput)) + { + using (Datalogics.PDFL.SignDoc sigDoc = new Datalogics.PDFL.SignDoc()) + { + // Setup Sign params + sigDoc.FieldID = SignatureFieldID.CreateFieldWithQualifiedName; + sigDoc.FieldName = "Signature_es_:signatureblock"; + + // Set credential related attributes + sigDoc.DigestCategory = DigestCategory.Sha384; + sigDoc.CredentialDataFormat = CredentialDataFmt.NonPFX; + sigDoc.SetNonPfxSignerCert(sPEMCert, 0, CredentialStorageFmt.OnDisk); + sigDoc.SetNonPfxPrivateKey(sPEMKey, 0, CredentialStorageFmt.OnDisk); + + // Set the signature type to PAdES (PDF Advanced Electronic Signatures). + // This produces an ETSI.CAdES.detached signature conforming to the + // PAdES baseline profile without a signature policy. + sigDoc.DocSignType = SignatureType.PADES; + + // Setup the signer information + // (Logo image is optional) + sigDoc.SetSignerInfo(sLogo, 0.5F, "John Doe", "Chicago, IL", "Approval", "Datalogics, Inc.", + DisplayTraits.KDisplayAll); + + // Set the size and location of the signature box (optional) + // If not set, invisible signature will be placed on first page + sigDoc.SignatureBoxPageNumber = 0; + sigDoc.SignatureBoxRectangle = new Rect(100, 300, 400, 400); + + // Setup Save params + sigDoc.OutputPath = sOutput; + + // Finally, sign and save the document + sigDoc.AddDigitalSignature(doc); + } + } + } + } + } +} diff --git a/Security/AddBasicPAdESElectronicSignature/AddBasicPAdESElectronicSignature.csproj b/Security/AddBasicPAdESElectronicSignature/AddBasicPAdESElectronicSignature.csproj new file mode 100644 index 0000000..99c0772 --- /dev/null +++ b/Security/AddBasicPAdESElectronicSignature/AddBasicPAdESElectronicSignature.csproj @@ -0,0 +1,62 @@ + + + + + Debug + x64 + {C7DF1472-B78F-402E-8841-52D2CB2B4725} + Exe + AddBasicPAdESElectronicSignature + AddBasicPAdESElectronicSignature + v4.7.2 + 512 + true + true + + + + + x64 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x64 + pdbonly + false + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + 18.* + + + + + + + \ No newline at end of file diff --git a/Security/AddBasicPAdESElectronicSignature/AddBasicPAdESElectronicSignature.sln b/Security/AddBasicPAdESElectronicSignature/AddBasicPAdESElectronicSignature.sln new file mode 100644 index 0000000..f4cff86 --- /dev/null +++ b/Security/AddBasicPAdESElectronicSignature/AddBasicPAdESElectronicSignature.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36414.22 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddBasicPAdESElectronicSignature", "AddBasicPAdESElectronicSignature.csproj", "{C7DF1472-B78F-402E-8841-52D2CB2B4725}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C7DF1472-B78F-402E-8841-52D2CB2B4725}.Debug|x64.ActiveCfg = Debug|x64 + {C7DF1472-B78F-402E-8841-52D2CB2B4725}.Debug|x64.Build.0 = Debug|x64 + {C7DF1472-B78F-402E-8841-52D2CB2B4725}.Release|x64.ActiveCfg = Release|x64 + {C7DF1472-B78F-402E-8841-52D2CB2B4725}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1320D004-1376-4D4F-BFD2-A33DC360756F} + EndGlobalSection +EndGlobal diff --git a/Security/AddBasicPAdESElectronicSignature/App.config b/Security/AddBasicPAdESElectronicSignature/App.config new file mode 100644 index 0000000..c8f3758 --- /dev/null +++ b/Security/AddBasicPAdESElectronicSignature/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Security/README.md b/Security/README.md index b960e4f..0d4760c 100644 --- a/Security/README.md +++ b/Security/README.md @@ -1,3 +1,6 @@ +## ***AddBasicPAdESElectronicSignature*** +Demonstrates adding a PAdES B-T baseline electronic signature to a PDF document. + ## ***AddDigitalSignatureCMS*** Demonstrates adding a digital signature with a logo to a PDF document.