Skip to content

957004_ex Added Added validate and classify digital signatures in a PDF sample #161

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35707.178 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Validate-and-classify-digital-signatures", "Validate-and-classify-digital-signatures\Validate-and-classify-digital-signatures.csproj", "{7048D610-0768-4A32-BB1E-B6840910C698}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7048D610-0768-4A32-BB1E-B6840910C698}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7048D610-0768-4A32-BB1E-B6840910C698}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7048D610-0768-4A32-BB1E-B6840910C698}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7048D610-0768-4A32-BB1E-B6840910C698}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;

//Get the stream from the document
using (FileStream documentStream = new FileStream(Path.GetFullPath(@"Data/Input.pdf"), FileMode.Open, FileAccess.Read))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the input document with trial watermark content

{
// Load the signed PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream);

// Get the PDF form
PdfLoadedForm form = loadedDocument.Form;

// Initialize flag to detect timestamp signatures
bool isTimeStampSignature = false;

// Loop through all form fields in reverse
for (int i = form.Fields.Count - 1; i >= 0; i--)
{
PdfLoadedField field = form.Fields[i] as PdfLoadedField;

// Check if the field is a signature field
if (field is PdfLoadedSignatureField)
{
PdfLoadedSignatureField signatureField = field as PdfLoadedSignatureField;
Console.WriteLine("Signature field name: " + signatureField.Name);

// Validate the signature
PdfSignatureValidationResult result = signatureField.ValidateSignature();

if (result != null)
{
// Check if it's a timestamp signature
if (result.TimeStampInformation != null && result.TimeStampInformation.IsDocumentTimeStamp)
{
isTimeStampSignature = true;
Console.WriteLine("Signature is a time stamp signature.");
}
else
{
bool isCAdES = false;

// Check if the cryptographic standard is CAdES
if (result.CryptographicStandard == CryptographicStandard.CADES)
{
isCAdES = true;
}

// Check if LTV (Long-Term Validation) is enabled
if (result.LtvVerificationInfo.IsLtvEnabled)
{
// Identify the type of long-term signature
if (isCAdES && isTimeStampSignature)
{
Console.WriteLine("LTA signature.");
}
else
{
Console.WriteLine("LTV signature.");
}
}
else
{
Console.WriteLine("No LTV signature.");
}
}
}
else
{
Console.WriteLine("Signature is not valid.");
}
}
}
// Close the PDF document.
loadedDocument.Close(true);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Validate_and_classify_digital_signatures</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="*" />
</ItemGroup>

</Project>
Loading