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.

Fri Nov 22, 2019 8:14 pm

Hi,

In this line:
Code: Select all
PdfCertificate certificate = new PdfCertificate(certificateBytes, password);


An exception occurred:
com.spire.pdf.packages.sprHUB: Undefined length encoding.
at com.spire.pdf.packages.sprEub.<init>(ASN1.java:52)
at com.spire.pdf.packages.sprVtb.spr (X509Certificate.java:51)
at com.spire.pdf.packages.sprVtb.<init>(X509Certificate.java:173)
at com.spire.ms.System.Security.Cryptography.X509Certificates.X509Certificate.spr (X509Certificate.java:169)
at com.spire.ms.System.Security.Cryptography.X509Certificates.X509Certificate2.spr (X509Certificate2.java:347)
at com.spire.ms.System.Security.Cryptography.X509Certificates.X509Certificate2.spr (X509Certificate2.java:382)
at com.spire.ms.System.Security.Cryptography.X509Certificates.X509Certificate2.<init>(X509Certificate2.java:57)
at com.spire.pdf.security.PdfCertificate.<init>(Unknown Source)


If anyone needs any information to help me troubleshoot, contact me!

Tks

rsdatasoftware
 
Posts: 1
Joined: Mon Nov 18, 2019 8:52 pm

Mon Nov 25, 2019 2:58 am

Hi,

Thanks for your inquiry. Sorry for reply late for weekend.
I made an initial test with Spire.PDF for Java Version:2.11.4 but didn't reproduce your issue.

To help us investigate your issue accurately, could you please offer us the following information?
1. Your input Pdf file(if any).
2. Your input certificate file and the password of it.
3. The complete code you were using which could reproduce your issue directly.
4. The OS and Region information, e.g. Win7 64bit, China/Chinese.

You could upload them here or send us(support@e-iceblue.com) via email.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Tue Nov 26, 2019 4:05 am

Hi,

Thanks for your information via email.
I have reproduced your issue and logged it into our bug tracking system. Once there is any progress, we will inform you.
Sorry for the inconvenience caused.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Fri Nov 29, 2019 6:07 am

Hi,

Hope you are doing well.
About the previous issue(PdfCertificate not working in Java), considering the emergency of your situation, we have compiled a temporary version for you. Please download and test the package from the following link.
http://www.e-iceblue.com/downloads/TempVersion/Spire.Pdf_2.11.5.zip

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Tue May 17, 2022 12:43 pm

i am getting this error unable to decode this
here is the my code
code:
public void sing(ActionEvent actionEvent) {
//Apply license
FileDialog dialog = new FileDialog((Frame)null, "Select File to Open");
dialog.setMode(FileDialog.LOAD);
dialog.setVisible(true);
String file = dialog.getDirectory();
String file1=dialog.getFile();
String filepath=file + file1;
System.out.println(filepath);
//Load pdf

String docPath = "C:\\Users\\Satyam\\Desktop\\pdf2\\a.pdf";
PdfDocument doc = new PdfDocument(docPath);
int num = doc.getPages().getCount();
//Sign each page
String newPath = docPath;
for (int sCnt = 0; sCnt < 1; sCnt++) {
newPath = newPath.replace(".pdf", "-2.pdf");
for (int i = 0; i < num; i++) {

PdfCertificate digi = new PdfCertificate(filepath.getBytes(StandardCharsets.UTF_8));
PdfSignature signature = new PdfSignature(doc, doc.getPages().get(i), digi, "Digital");


Rectangle2D rect = new Rectangle2D.Float();
//rect.setRect(300, 200, 100, 50);
rect.setRect(100 * (sCnt + 1), 50 * (sCnt + 1), 100, 50);
signature.setBounds(rect);

/*signature.setDistinguishedName("DN:");
signature.setNameLabel("Digital Signed By:") ;
signature.setName("Ankush") ;
signature.setContactInfo("Lisa") ;
signature.setDate(DateTime.toJava(DateTime.getNow())) ;
signature.setCertificated(false) ;*/

signature.setDocumentPermissions(PdfCertificationFlags.Allow_Form_Fill);
signature.setDocumentPermissions(PdfCertificationFlags.Forbid_Changes);

//save and reload"
//doc.saveToFile("C:\\Users\\Satyam\\Desktop\\pdf\\b-1.pdf");
doc.saveToFile(newPath);

}
}

Shamsulhuda
 
Posts: 2
Joined: Tue Apr 19, 2022 8:05 am

Wed May 18, 2022 8:52 am

Hi,

Thank you for your inquiry.
The method filepath.getBytes(StandardCharsets.UTF_8) you used to get the certificate data is incorrect. Please change your code as below to load certificate.
Please feel free to contact me if you have any questions.
Code: Select all
      //load from file
      //PdfCertificate digi = new PdfCertificate(filepath,password);
      //load from byte array
      PdfCertificate digi = new PdfCertificate(getFileBytes(pfxPath),password);
      private static byte[] getFileBytes(String file) {
      try {
            File f = new File(file);
            int length = (int) f.length();
            byte[] data = new byte[length];
            new FileInputStream(f).read(data);
            return data;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } 


Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Wed Aug 03, 2022 2:11 am

Hi,

Hope you are doing well!
Has your problem been effectively solved now? Can you give us some feedback at your convenience?
Thanks in advance.

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Return to Spire.PDF