-
Notifications
You must be signed in to change notification settings - Fork 48
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
sameerkhan001
wants to merge
1
commit into
master
Choose a base branch
from
957004_ex
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions
22
...alidate-and-classify-digital-signatures/.NET/Validate-and-classify-digital-signatures.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,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 added
BIN
+402 KB
...-classify-digital-signatures/.NET/Validate-and-classify-digital-signatures/Data/Input.pdf
Binary file not shown.
75 changes: 75 additions & 0 deletions
75
...-and-classify-digital-signatures/.NET/Validate-and-classify-digital-signatures/Program.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,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)) | ||
{ | ||
// 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); | ||
} |
15 changes: 15 additions & 0 deletions
15
.../Validate-and-classify-digital-signatures/Validate-and-classify-digital-signatures.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,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> |
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.
There was a problem hiding this comment.
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