PDF Two signatures using two different certificate - First Broken

Hello, I have a problem with signing PDF file with 2 signatures.
I use the latest version Syncfusion.Pdf.WinForms 18.1.0.46 from nuget.

Steps:
  1. I have clean PDF file
  2. Sign by First cert
  3. Sign by Second cert
Result is that this First signature is broken and we can't see first Cert details. 
It' look like if we sign the second time the library didn't know details about the first certificate.

Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("XXX");

            var cert1 = new X509Certificate2(@"../../Data/keyStore1.p12", "pass1234");
            var cert2 = new X509Certificate2(@"../../Data/keyStore2.p12", "pass1234");

            //Creates a certificate instance from PFX file with private key
            PdfCertificate pdfCert = new PdfCertificate(cert1);
            PdfCertificate pdfCert2 = new PdfCertificate(cert2);

            //Loads a PDF document
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../Data/TestPDF.pdf");
            //Creates a digital signature
            PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], pdfCert, "First");

            //Saves and closes the document
            MemoryStream ms = new MemoryStream();
            loadedDocument.Save(ms);
            loadedDocument.Close(true);

            //Loads a PDF document
            PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(ms);
            //Creates a digital signature
            PdfSignature pdfSignature = new PdfSignature(loadedDocument1, loadedDocument1.Pages[0], pdfCert2, "Sec");

            loadedDocument1.Save("Output.pdf");
            loadedDocument1.Close(true);

            Process.Start("Output.pdf");

Attachment: Sign2Certs_eee3fd50.zip

5 Replies

GK Gowthamraj Kumar Syncfusion Team April 30, 2020 02:22 PM UTC

Hi Michal, 
  
Thank you for using Syncfusion products. 
We were able to reproduce the reported signature issue in our latest NuGet with the provided details. Currently, we are validating this and we will update the further details on 5th May 2020.  
  
Regards, 
Gowthamraj K 



GK Gowthamraj Kumar Syncfusion Team May 5, 2020 10:25 AM UTC

Hi Michal, 

On further analysis, we found that the first signature is broken due to adding of a trial watermark. So kindly use the licensed assemblies to overcome this issue. 


Regards, 
Gowthamraj K 



MS Michal Stachyra May 5, 2020 02:08 PM UTC

Yes, but if you look at signature details in Adobe you will see that two signatures has the same certificate called 'sec'.
Is it correct behavior? 

Attachment: screen_pdf_sign_4318c32d.zip


GK Gowthamraj Kumar Syncfusion Team May 6, 2020 01:26 PM UTC

Hi Michal, 
 
Thank you for your update. 
 
We have checked the reported issue with the provided details. We have modified the code snippet and tried the conversion, now the signature added properly. We have shared the output document for your reference. To overcome this issue, you can use this below code snippet in your end and let us know the result.   
   
   
Please refer the below code snippet to overcome this issue,   
 
var cert1 = new X509Certificate2(@"../../Data/keyStore1.p12", "pass1234"); 
var cert2 = new X509Certificate2(@"../../Data/keyStore2.p12", "pass1234"); 
 
//Creates a certificate instance from PFX file with private key 
PdfCertificate pdfCert = new PdfCertificate(cert1); 
             
//Loads a PDF document 
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("../../Data/TestPDF.pdf"); 
//Creates a digital signature 
PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], pdfCert, "First"); 
 
//Saves and closes the document 
MemoryStream ms = new MemoryStream(); 
loadedDocument.Save(ms); 
loadedDocument.Close(true); 
 
//Loads a PDF document 
PdfLoadedDocument loadedDocument1 = new PdfLoadedDocument(ms); 
PdfCertificate pdfCert2 = new PdfCertificate(cert2); 
//Creates a digital signature 
PdfSignature pdfSignature = new PdfSignature(loadedDocument1, loadedDocument1.Pages[0], pdfCert2, "Sec"); 
 
loadedDocument1.Save("Output.pdf"); 
loadedDocument1.Close(true); 
 
Process.Start("Output.pdf"); 
 
 
Please let us know if you any further assistance with this.   
 
Regards, 
Gowthamraj K 



MS Michal Stachyra May 6, 2020 02:20 PM UTC

It's works :) 
So if we move this line "PdfCertificate pdfCert2 = new PdfCertificate(cert2);" close to creating next Signature will fix that.

Thanks for helping and quick solve my issue.

Loader.
Up arrow icon