Skip to content
Merged
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="Digital-Signature-Validation/Digital-Signature-Validation.csproj" />
</Solution>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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>Digital_Signature_Validation</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;

string dataPath = Path.GetFullPath(@"Data/");

// Load signed PDF document
using PdfLoadedDocument ldoc = new PdfLoadedDocument(Path.GetFullPath(@"Data/Input.pdf"));

// Get signature field
PdfLoadedSignatureField lSigFld = ldoc.Form.Fields[0] as PdfLoadedSignatureField;

// Root and Intermediate Certificates
X509CertificateCollection collection = new X509CertificateCollection();

string[] certificates =
{
"Root.cer",
"Intermediate0.cer",
"Intermediate1.cer"
};

foreach (string certFile in certificates)
{
byte[] certData = File.ReadAllBytes(Path.Combine(dataPath, certFile));

X509Certificate2 certificate = new X509Certificate2(certData);

collection.Add(certificate);
}

// Validate signature
PdfSignatureValidationResult result = lSigFld.ValidateSignature(collection);

StringBuilder builder = new StringBuilder();

builder.AppendLine("Signature is " + result.SignatureStatus);
builder.AppendLine();
builder.AppendLine("----------Validation Summary----------");
builder.AppendLine();

// Modified check
if (result.IsDocumentModified)
{
builder.AppendLine("The document has been altered or corrupted since the signature was applied.");
}
else
{
builder.AppendLine("The document has not been modified since the signature was applied.");
}

// Certificate details
builder.AppendLine("Digitally signed by: " + lSigFld.Signature.Certificate.IssuerName);

builder.AppendLine("Valid From: " + lSigFld.Signature.Certificate.ValidFrom);

builder.AppendLine("Valid To: " + lSigFld.Signature.Certificate.ValidTo);

builder.AppendLine("Signature Algorithm: " + result.SignatureAlgorithm);

builder.AppendLine("Hash Algorithm: " + result.DigestAlgorithm);

// Revocation details
builder.AppendLine("OCSP Revocation Status: " + result.RevocationResult.OcspRevocationStatus);

if (result.RevocationResult.OcspRevocationStatus == RevocationStatus.None && result.RevocationResult.IsRevokedCRL)
{
builder.AppendLine("CRL is revoked.");
}

builder.AppendLine();
builder.AppendLine("--------Revocation Information---------");
builder.AppendLine();

foreach (PdfSignerCertificate signerCertificate in result.SignerCertificates)
{
if (signerCertificate.OcspCertificate != null)
{
builder.AppendLine("------------OCSP Certificate-------------");

foreach (X509Certificate2 item in signerCertificate.OcspCertificate.Certificates)
{
builder.AppendLine("The OCSP Response was signed by: " + item.SubjectName.Name);
}

builder.AppendLine("Is Embedded: " + signerCertificate.OcspCertificate.IsEmbedded);

builder.AppendLine("Valid From: " + signerCertificate.OcspCertificate.ValidFrom);

builder.AppendLine("Valid To: " + signerCertificate.OcspCertificate.ValidTo);

builder.AppendLine();
}

if (signerCertificate.CrlCertificate != null)
{
builder.AppendLine("------------CRL Certificate--------------");

foreach (X509Certificate2 item in signerCertificate.CrlCertificate.Certificates)
{
builder.AppendLine("The CRL was signed by: " + item.SubjectName.Name);
}

builder.AppendLine("Is Embedded: " + signerCertificate.CrlCertificate.IsEmbedded);
builder.AppendLine("Valid From: " + signerCertificate.CrlCertificate.ValidFrom);
builder.AppendLine("Valid To: " + signerCertificate.CrlCertificate.ValidTo);
builder.AppendLine();
}
}
//Save to file
File.WriteAllText(Path.GetFullPath(@"Output/Output.txt"),builder.ToString());
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
{
extractedText += page.ExtractText();
}
// Display the extracted text in the console
Console.WriteLine("Extracted text from the entire document: " + extractedText);
// Save the extracted text content to a TXT file
File.WriteAllText(Path.GetFullPath(@"Output/Output.txt"), extractedText);
}
Loading