Verify Pdf hasn't modified after adding signature
I am using PDF component for adding digital signatures to the pdf document.
Here is how I am adding the signature
PdfLoadedDocument document = new PdfLoadedDocument("DigitalSignaturee2.pdf");
PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;
//Creates a signature field.
PdfSignatureField signatureField = new PdfSignatureField(page, "SignatureField");
signatureField.Bounds = new RectangleF(0, 0, 100, 100);
signatureField.Signature = new PdfSignature(document, page, new PdfCertificate(@"C:\Users\Public\Documents\Syncfusion\ASP.NET MVC - EJ2\16.3.0.21\App_Data\PDF\PDF.pfx", "syncfusion"), "SignatureField");
signatureField.Signature.Reason = "I am author of this document";
document.Form.Fields.Add(signatureField);
document.Save();
//Closes the document
document.Close(true);
I can get the document certificate as of volume 4 release. But how can I verify that document hasn't modified after the signature was added.
Here is the code for the signature retrieval.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("DigitalSignaturee2.pdf");
//Gets the page of the document
PdfLoadedPage page1 = loadedDocument.Pages[0] as PdfLoadedPage;
PdfLoadedSignatureField field2 = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
//Get PDF Certificate instance from signature field
PdfCertificate certificate = field2.Signature.Certificate;
//Get the certificate details
string subjectName = certificate.SubjectName;
string issuerName = certificate.IssuerName;
SIGN IN To post a reply.
2 Replies
KC
Karthikeyan Chandrasekar
Syncfusion Team
December 20, 2018 12:26 PM UTC
Hi Muhammad,
Greetings from Syncfusion.
At present, we don’t have a support to validate the digital signature for signed PDF and we have logged feature request. At present we do not have any immediate plan to implement these features.
At present, we don’t have a support to validate the digital signature for signed PDF and we have logged feature request. At present we do not have any immediate plan to implement these features.
The implementation of this feature would greatly depend on the factors such as time complexity and code compatibility. The feature implementation will be available in any of our upcoming release. We will update once the feature has been implemented.
Regards,
Karthikeyan
SL
Sowmiya Loganathan
Syncfusion Team
September 23, 2019 07:09 AM UTC
Hi Muhammad,
We glad to announce that the feature “Support for validating digital signatures in existing PDF document” is implemented and it is included in our Essential Studio 2019 Volume 3 Beta release v17.3.0.9. This is rolled out and is available for download under the following link,
Please find the code snippet to illustrate this from below,
|
//Load an existing signed PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
//Get signature field
PdfLoadedSignatureField signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
//X509Certificate2Collection to check the signer's identity using root certificates
X509CertificateCollection collection = new X509CertificateCollection();
//Create new X509Certificate2 with the root certificate
X509Certificate2 certificate = new X509Certificate2("PDF.pfx", "syncfusion");
//Add the certificate to the collection
collection.Add(certificate);
//Validate signature and get the validation result
PdfSignatureValidationResult result = signatureField.ValidateSignature(collection);
//Checks whether the signature is valid or not
SignatureStatus status = result.SignatureStatus;
//Checks whether the document is modified or not
bool isModified = result.IsDocumentModified;
//Signature details
string issuerName = signatureField.Signature.Certificate.IssuerName;
DateTime validFrom = signatureField.Signature.Certificate.ValidFrom;
DateTime validTo = signatureField.Signature.Certificate.ValidTo;
string signatureAlgorithm = result.SignatureAlgorithm;
DigestAlgorithm digestAlgorithm = result.DigestAlgorithm;
//Revocation validation details
RevocationResult revocationDetails = result.RevocationResult;
RevocationStatus revocationStatus = revocationDetails.OcspRevocationStatus;
bool isRevokedCRL = revocationDetails.IsRevokedCRL;
//Checks whether the signature is valid or not based on the overall validation
bool isSignatureValid = result.IsSignatureValid;
//Close the document
loadedDocument.Close(true); |
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.
Regards,
Sowmiya Loganathan
SIGN IN To post a reply.
- 2 Replies
- 3 Participants
-
MA Muhammad Ahmad
- Dec 19, 2018 01:43 PM UTC
- Sep 23, 2019 07:09 AM UTC