Skip to content

Commit d4274fd

Browse files
Merge pull request #63 from datalogics-rgailiunas/timestamp
[APDFL-6432] Add DigSig RFC3161 TimeStamp Sample
2 parents f953cd2 + 7272cd4 commit d4274fd

11 files changed

Lines changed: 182 additions & 12 deletions

.github/workflows/test-net-framework-samples.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ jobs:
9393
'Other/StreamIO/',
9494
'Printing/PrintPDF/',
9595
'Printing/PrintPDFGUI/',
96-
'Security/AddDigitalSignature/',
96+
'Security/AddDigitalSignatureCMS/',
97+
'Security/AddDigitalSignatureRFC3161/',
9798
'Security/AddRegexRedaction/',
9899
'Security/Redactions/',
99100
'Text/AddGlyphs/',

Samples.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegexTextSearch", "Text\Reg
180180
EndProject
181181
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextExtract", "Text\TextExtract\TextExtract.csproj", "{11C4A647-3DDA-41A5-855C-E14EDF1BFFDE}"
182182
EndProject
183-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddDigitalSignature", "Security\AddDigitalSignature\AddDigitalSignature.csproj", "{AB753937-DF3D-4B06-B475-D3B597D32BC5}"
183+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddDigitalSignatureCMS", "Security\AddDigitalSignatureCMS\AddDigitalSignatureCMS.csproj", "{AB753937-DF3D-4B06-B475-D3B597D32BC5}"
184+
EndProject
185+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddDigitalSignatureRFC3161", "Security\AddDigitalSignatureRFC3161\AddDigitalSignatureRFC3161.csproj", "{74FA984E-AB89-475A-9077-9D612DE12AEC}"
184186
EndProject
185187
Global
186188
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -548,6 +550,10 @@ Global
548550
{AB753937-DF3D-4B06-B475-D3B597D32BC5}.Debug|x64.Build.0 = Debug|x64
549551
{AB753937-DF3D-4B06-B475-D3B597D32BC5}.Release|x64.ActiveCfg = Release|x64
550552
{AB753937-DF3D-4B06-B475-D3B597D32BC5}.Release|x64.Build.0 = Release|x64
553+
{74FA984E-AB89-475A-9077-9D612DE12AEC}.Debug|x64.ActiveCfg = Debug|x64
554+
{74FA984E-AB89-475A-9077-9D612DE12AEC}.Debug|x64.Build.0 = Debug|x64
555+
{74FA984E-AB89-475A-9077-9D612DE12AEC}.Release|x64.ActiveCfg = Release|x64
556+
{74FA984E-AB89-475A-9077-9D612DE12AEC}.Release|x64.Build.0 = Release|x64
551557
EndGlobalSection
552558
GlobalSection(SolutionProperties) = preSolution
553559
HideSolutionNode = FALSE

Security/AddDigitalSignature/AddDigitalSignature.cs renamed to Security/AddDigitalSignatureCMS/AddDigitalSignatureCMS.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55

66
/*
77
*
8-
* This sample program demonstrates the use of AddDigitalSignature.
8+
* This sample program demonstrates the use of AddDigitalSignature for CMS signature type.
99
*
1010
* Copyright (c) 2025, Datalogics, Inc. All rights reserved.
1111
*
1212
*/
13-
namespace AddDigitalSignature
13+
namespace AddDigitalSignatureCMS
1414
{
15-
class AddDigitalSignature
15+
class AddDigitalSignatureCMS
1616
{
1717
static void Main(string[] args)
1818
{
19-
Console.WriteLine("AddDigitalSignature Sample:");
19+
Console.WriteLine("AddDigitalSignatureCMS Sample:");
2020

2121
using (new Library())
2222
{
2323
Console.WriteLine("Initialized the library.");
2424

2525
String sInput = Library.ResourceDirectory + "Sample_Input/SixPages.pdf";
2626
String sLogo = Library.ResourceDirectory + "Sample_Input/ducky_alpha.tif";
27-
String sOutput = "DigSig-out.pdf";
27+
String sOutput = "DigSigCMS-out.pdf";
2828

2929
String sDERCert = Library.ResourceDirectory + "Sample_Input/Credentials/DER/RSA_certificate.der";
3030
String sDERKey = Library.ResourceDirectory + "Sample_Input/Credentials/DER/RSA_privKey.der";
@@ -55,6 +55,10 @@ static void Main(string[] args)
5555
sigDoc.SetNonPfxSignerCert(sDERCert, 0, CredentialStorageFmt.OnDisk);
5656
sigDoc.SetNonPfxPrivateKey(sDERKey, 0, CredentialStorageFmt.OnDisk);
5757

58+
// Set the signature type to be used.
59+
// The available types are defined in the SignatureType enum. Default CMS.
60+
sigDoc.DocSignType = SignatureType.CMS;
61+
5862
// Setup the signer information
5963
// (Logo image is optional)
6064
sigDoc.SetSignerInfo(sLogo, 0.5F, "John Doe", "Chicago, IL", "Approval", "Datalogics, Inc.",

Security/AddDigitalSignature/AddDigitalSignature.csproj renamed to Security/AddDigitalSignatureCMS/AddDigitalSignatureCMS.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
77
<ProjectGuid>{AB753937-DF3D-4B06-B475-D3B597D32BC5}</ProjectGuid>
88
<OutputType>Exe</OutputType>
9-
<RootNamespace>AddDigitalSignature</RootNamespace>
10-
<AssemblyName>AddDigitalSignature</AssemblyName>
9+
<RootNamespace>AddDigitalSignatureCMS</RootNamespace>
10+
<AssemblyName>AddDigitalSignatureCMS</AssemblyName>
1111
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
1212
<FileAlignment>512</FileAlignment>
1313
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
@@ -45,7 +45,7 @@
4545
<Reference Include="System.Xml" />
4646
</ItemGroup>
4747
<ItemGroup>
48-
<Compile Include="AddDigitalSignature.cs" />
48+
<Compile Include="AddDigitalSignatureCMS.cs" />
4949
</ItemGroup>
5050
<ItemGroup>
5151
<None Include="App.config" />

Security/AddDigitalSignature/AddDigitalSignature.sln renamed to Security/AddDigitalSignatureCMS/AddDigitalSignatureCMS.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
22
# Visual Studio Version 17
33
VisualStudioVersion = 17.13.35818.85
44
MinimumVisualStudioVersion = 10.0.40219.1
5-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddDigitalSignature", "AddDigitalSignature.csproj", "{3790CE63-DB43-4F16-8226-BDFEFA25BCDD}"
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddDigitalSignatureCMS", "AddDigitalSignatureCMS.csproj", "{3790CE63-DB43-4F16-8226-BDFEFA25BCDD}"
66
EndProject
77
Global
88
GlobalSection(SolutionConfigurationPlatforms) = preSolution
File renamed without changes.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Datalogics.PDFL;
5+
6+
/*
7+
*
8+
* This sample program demonstrates the use of AddDigitalSignature for RFC3161 timestamp signature type.
9+
*
10+
* Copyright (c) 2025, Datalogics, Inc. All rights reserved.
11+
*
12+
*/
13+
namespace AddDigitalSignatureRFC3161
14+
{
15+
class AddDigitalSignatureRFC3161
16+
{
17+
static void Main(string[] args)
18+
{
19+
Console.WriteLine("AddDigitalSignatureRFC3161 Sample:");
20+
21+
using (new Library())
22+
{
23+
Console.WriteLine("Initialized the library.");
24+
25+
String sInput = Library.ResourceDirectory + "Sample_Input/CreateAcroForm2h.pdf";
26+
27+
String sOutput = "DigSigRFC3161-out.pdf";
28+
29+
if (args.Length > 0)
30+
sInput = args[0];
31+
32+
if (args.Length > 1)
33+
sOutput = args[1];
34+
35+
Console.WriteLine("Input file: " + sInput);
36+
Console.WriteLine("Writing to output: " + sOutput);
37+
38+
using (Document doc = new Document(sInput))
39+
{
40+
using (Datalogics.PDFL.SignDoc sigDoc = new Datalogics.PDFL.SignDoc())
41+
{
42+
// Setup Sign params
43+
sigDoc.FieldID = SignatureFieldID.SearchForFirstUnsignedField;
44+
45+
// Set signing attributes
46+
sigDoc.DigestCategory = DigestCategory.Sha256;
47+
48+
// Set the signature type to be used, RFC3161/TimeStamp.
49+
// The available types are defined in the SignatureType enum. Default CMS.
50+
sigDoc.DocSignType = SignatureType.RFC3161;
51+
52+
// Setup Save params
53+
sigDoc.OutputPath = sOutput;
54+
55+
// Finally, sign and save the document
56+
sigDoc.AddDigitalSignature(doc);
57+
58+
Console.WriteLine();
59+
}
60+
}
61+
}
62+
}
63+
}
64+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">x64</Platform>
7+
<ProjectGuid>{74FA984E-AB89-475A-9077-9D612DE12AEC}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>AddDigitalSignatureRFC3161</RootNamespace>
10+
<AssemblyName>AddDigitalSignatureRFC3161</AssemblyName>
11+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
<NuGetPackageImportStamp>
16+
</NuGetPackageImportStamp>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
19+
<PlatformTarget>x64</PlatformTarget>
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
29+
<PlatformTarget>x64</PlatformTarget>
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>false</Optimize>
32+
<OutputPath>bin\Release\</OutputPath>
33+
<DefineConstants>TRACE</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Xml.Linq" />
41+
<Reference Include="System.Data.DataSetExtensions" />
42+
<Reference Include="Microsoft.CSharp" />
43+
<Reference Include="System.Data" />
44+
<Reference Include="System.Net.Http" />
45+
<Reference Include="System.Xml" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="AddDigitalSignatureRFC3161.cs" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<None Include="App.config" />
52+
</ItemGroup>
53+
<ItemGroup>
54+
<PackageReference Include="Adobe.PDF.Library.LM.NETFramework">
55+
<Version>18.*</Version>
56+
</PackageReference>
57+
</ItemGroup>
58+
<ItemGroup>
59+
<Folder Include="Properties\" />
60+
</ItemGroup>
61+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
62+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.13.35818.85
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddDigitalSignatureRFC3161", "AddDigitalSignatureRFC3161.csproj", "{74FA984E-AB89-475A-9077-9D612DE12AEC}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|x64 = Debug|x64
10+
Release|x64 = Release|x64
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{74FA984E-AB89-475A-9077-9D612DE12AEC}.Debug|x64.ActiveCfg = Debug|x64
14+
{74FA984E-AB89-475A-9077-9D612DE12AEC}.Debug|x64.Build.0 = Debug|x64
15+
{74FA984E-AB89-475A-9077-9D612DE12AEC}.Release|x64.ActiveCfg = Release|x64
16+
{74FA984E-AB89-475A-9077-9D612DE12AEC}.Release|x64.Build.0 = Release|x64
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {08DC1B85-4756-4272-B76A-197A8E79394D}
23+
EndGlobalSection
24+
EndGlobal
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

0 commit comments

Comments
 (0)