-
Notifications
You must be signed in to change notification settings - Fork 9
Add PAdES baseline electronic signature sample for .NET Framework #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
datalogics-rheryani
merged 2 commits into
datalogics:develop
from
datalogics-saharay:APDFL-6595-add-PAdES-without-policy-sample
Mar 11, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
Security/AddBasicPAdESElectronicSignature/AddBasicPAdESElectronicSignature.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
Security/AddBasicPAdESElectronicSignature/AddBasicPAdESElectronicSignature.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
| <PropertyGroup> | ||
| <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
| <Platform Condition=" '$(Platform)' == '' ">x64</Platform> | ||
| <ProjectGuid>{C7DF1472-B78F-402E-8841-52D2CB2B4725}</ProjectGuid> | ||
| <OutputType>Exe</OutputType> | ||
| <RootNamespace>AddBasicPAdESElectronicSignature</RootNamespace> | ||
| <AssemblyName>AddBasicPAdESElectronicSignature</AssemblyName> | ||
| <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||
| <FileAlignment>512</FileAlignment> | ||
| <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
| <Deterministic>true</Deterministic> | ||
| <NuGetPackageImportStamp> | ||
| </NuGetPackageImportStamp> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> | ||
| <PlatformTarget>x64</PlatformTarget> | ||
| <DebugSymbols>true</DebugSymbols> | ||
| <DebugType>full</DebugType> | ||
| <Optimize>false</Optimize> | ||
| <OutputPath>bin\Debug\</OutputPath> | ||
| <DefineConstants>DEBUG;TRACE</DefineConstants> | ||
| <ErrorReport>prompt</ErrorReport> | ||
| <WarningLevel>4</WarningLevel> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> | ||
| <PlatformTarget>x64</PlatformTarget> | ||
| <DebugType>pdbonly</DebugType> | ||
| <Optimize>false</Optimize> | ||
| <OutputPath>bin\Release\</OutputPath> | ||
| <DefineConstants>TRACE</DefineConstants> | ||
| <ErrorReport>prompt</ErrorReport> | ||
| <WarningLevel>4</WarningLevel> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Reference Include="System" /> | ||
| <Reference Include="System.Core" /> | ||
| <Reference Include="System.Xml.Linq" /> | ||
| <Reference Include="System.Data.DataSetExtensions" /> | ||
| <Reference Include="Microsoft.CSharp" /> | ||
| <Reference Include="System.Data" /> | ||
| <Reference Include="System.Net.Http" /> | ||
| <Reference Include="System.Xml" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Compile Include="AddBasicPAdESElectronicSignature.cs" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <None Include="App.config" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Adobe.PDF.Library.LM.NETFramework"> | ||
| <Version>18.*</Version> | ||
| </PackageReference> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Folder Include="Properties\" /> | ||
| </ItemGroup> | ||
| <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
| </Project> |
24 changes: 24 additions & 0 deletions
24
Security/AddBasicPAdESElectronicSignature/AddBasicPAdESElectronicSignature.sln
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <configuration> | ||
| <startup> | ||
| <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||
| </startup> | ||
| </configuration> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.