Verify Digital Signature

Verify Digital Signature

Forum member · Jul 29, 2021
Hello everyone, I'm using Dynamic PDF to export PDF with Digital Sign. But I want to know if exist something that when my customer upload again this PDF with his digital signature to verify if mine Signature is OK. Best regards

Re: Verify Digital Signature

Support · Jul 29, 2021
Hi, You can verify the signature contents in an existing PDF using DynamicPDF Core Suite for .NET. Here is a code sample. Please note, it will throw an exception if the data is invalid for the given signature. string input = @"Path for a singed PDF"; // Create a PdfDocument object using the source PDF that is being verified for signatures PdfDocument pdf = new PdfDocument(input); // Get the list of PdfSignatureField from the pdf document List<PdfSignatureField> signedSignatureFields = pdf.GetSignedSignatureFields(); PdfSignatureField pdfSignatureField = signedSignatureFields[0]; // Get the content that is signed using the selected signature field byte[] signatureContent = pdfSignatureField.SignatureContent; // Create a byte array to hold the data that is present in the signature range byte[] dataToVerify = new byte[pdfSignatureField.Range[0].Length + pdfSignatureField.Range[1].Length]; // Get all the PDF file data that is being validated byte[] fileData = File.ReadAllBytes(input); // Load the dataToVerify from the PDF, using the range of the signature Array.Copy(fileData, dataToVerify, pdfSignatureField.Range[0].Length); Array.Copy(fileData, pdfSignatureField.Range[1].StartIndex, dataToVerify, pdfSignatureField.Range[0].Length, pdfSignatureField.Range[1].Length); // Create a ContentInfo object using the data to be verified System.Security.Cryptography.Pkcs.ContentInfo contentInfo = new ContentInfo(dataToVerify); // Create a SignedCms object using contentInfo SignedCms signedCms = new SignedCms(contentInfo, true); // Decode the signature content signedCms.Decode(signatureContent); // Verify the signature. This method will throw an exception if the data is invalid for the given signature. //passing boolean as false will verify both signature and certificate chain. //passing true will verify only signature contents. signedCms.CheckSignature(true); Thanks, ceTe Software Support Team

Re: Verify Digital Signature

Forum member · Aug 2, 2021
Thanks very much. Works fine but is any way to check if a signature is the same with the original?

Re: Verify Digital Signature

Support · Aug 3, 2021
Hi, You can verify the signature contents using the above posted code sample, but DynamicPDF Core Suite product does not support detecting whether the signature is same as the original. Thanks, ceTe Software Support Team