Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Mar 22, 2023 7:37 am

1) I am using an USB token instead of a file (p12 / pfx certificate) to sign a PDF which contains multiple pages using a similar sample code as given to add / delete signature in a pdf.

2) When I check the signature validity in Adobe Acrobat DC, it says signature is invalid.

3) I tried to verify the signature of the signed PDF using "signature.verifySignature()", it throws error saying - '(Signature name) failed to verified'

4) The sample code we used for signing is shown below:
Code: Select all
                       X509Certificate x509Cert = (X509Certificate) DSign.keyStore.getCertificate(requestAlias); // getting the certificate data from the USB token using signature alias
                       PrivateKey privateKey = (PrivateKey) DSign.keyStore.getKey(requestAlias,
                            privateKeyPassword != null ? privateKeyPassword.toCharArray() : null);
                        File inputTempFile = File.createTempFile(fileName, ".pdf");
                        byte[] decoded = Base64.getDecoder().decode(requestPdfData.getBytes()); // requestPdfData is the pdf file got using base64 format
                        FileOutputStream fos = new FileOutputStream(inputTempFile);
                        fos.write(decoded);
                        fos.close();
                        String inputPdfPath = inputTempFile.getAbsolutePath();
                        String outputPdfPath = inputPdfPath.replace(".pdf", "_signed.pdf");
                       
                        PdfDocument doc = new PdfDocument();
                        doc.loadFromFile(inputPdfPath);
                       
                        PdfCertificate pdfCert = new PdfCertificate(x509Cert.getEncoded()); // Certificate data is got using the USB token which is encoded
                        //Create a PdfSignature object and specify its position and size
                        PdfSignature signature = new PdfSignature(doc, doc.getPages().get(0), pdfCert, "My signature");
                               
                        Rectangle2D rect = new Rectangle2D.Float();
                        rect.setFrame(new Point2D.Float((float) doc.getPages().get(0).getActualSize().getWidth() - 250, (float) doc.getPages().get(doc.getPages().getCount() - 1).getActualSize().getHeight() - signLocation), new Dimension(250, 100));
                        signature.setBounds(rect);
                       
                      //Set the graphics mode
                        signature.setGraphicMode(GraphicMode.Sign_Detail);
//                        signature.removeShowConfigureText(SignatureConfigureText.Distinguished_Name);
//                        signature.setName(partyName);
                        signature.setDateLabel("Date:");
                        signature.setDate(new java.util.Date());
                        signature.setReasonLabel("Reason: ");
                        signature.setReason("Online Approval\n");
//                        signature.setSignatureName("My Signature");

                        //Set the signature font
//                        signature.setSignInfoFont(new PdfFont(PdfFontFamily.Courier, 11f, PdfFontStyle.Regular));
                        signature.setSignDetailsFont(new PdfFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Bold));
//                        signature.setSignNameFont(new PdfFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Bold));
                        //Set the document permission
                        signature.setDocumentPermissions(PdfCertificationFlags.Forbid_Changes);
                        signature.setCertificated(true);

                        //Save to file
                        doc.saveToFile(outputPdfPath);
                        doc.close();                       
                       
                        File outputFile = new File(outputPdfPath);
                        byte[] fileContent = Files.readAllBytes(outputFile.toPath());
                        signedPdfData = Base64.getEncoder().encodeToString(fileContent);

mohan.ram
 
Posts: 2
Joined: Wed Mar 22, 2023 5:40 am

Thu Mar 23, 2023 11:06 am

Hi,

Thanks for your feedback.
I will investigate this issue and provide you with a solution ASAP. Sorry for the inconvenience caused.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 999
Joined: Tue Nov 15, 2022 3:59 am

Thu Mar 30, 2023 11:54 am

Hi Triste,
It has been a week and I still await a solution for this problem and the cause of the issue.

mohan.ram
 
Posts: 2
Joined: Wed Mar 22, 2023 5:40 am

Fri Mar 31, 2023 10:17 am

Hi,

Thank you for your inquiry regarding using a USB token for PDF file signing. We apologize for the delay in our response, as we needed to research and test the issue before getting back to you.
After testing, we were able to reproduce the problem you reported. I have logged this issue into our issue tracking system with the ticket number SPIREPDF-5905, our developers will investigate and fix it, sorry for the inconvenience caused. Once there are any updates available, I will inform you asap
Please let us know if you have any further questions or concerns, and we thank you for your understanding and support.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 999
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF