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 Nov 12, 2025 8:55 am

Hello, my company is evaluating Spire.PDF for Java and i’m testing the signatures functions. With the code below:

String filePathString = "mycert.pfx";
PdfCertificate cert = PdfCertificate(filePathString,"mypassword");

I have the error:
Exception in thread "main" com.spire.pdf.packages.sprbwu: Undefined length encoding.
at com.spire.pdf.packages.sprqpq.<init>(ASN1.java:52)
at com.spire.pdf.packages.spryuq.spr?(PKCS12.java:284)
at com.spire.pdf.packages.spryuq.<init>(PKCS12.java:273)
at com.spire.pdf.interactive.digitalsignatures.PdfCertificate.spr??(Unknown Source)
at com.spire.pdf.interactive.digitalsignatures.PdfCertificate.<init>(Unknown Source)
at spirepdfant.Spirepdfant.main(Spirepdfant.java:95)

I’m using Spire.Pdf.jar version 11.10.3 and a JDK 24 64 bit.

Obviously the problem is in my certificate since the ‘gary.pfx’ certificate i found in your samples is working well.
The same code with Spire.PDF for .NET (v. 11.11.1) and .NET Framework 4.6 is working.

My certificate is a regular certificate given to me from an italian government entity with my name inside and so on.

Can you help me?

mgasperi
 
Posts: 5
Joined: Thu Jul 27, 2023 2:50 pm

Wed Nov 12, 2025 9:37 am

Hello

Thank you for your inquiry.
The Spire.Pdf.jar version 9.13.0 you are using is relatively old. Our latest version is Spire.PDF for Java Version:11.10.3. We suggest that you use the latest version test again, since the Spire.PDF for.NET (v. 11.11.1) is also our latest NET version. Looking forward to your further testing feedback.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1533
Joined: Wed Apr 25, 2018 3:20 am

Wed Nov 12, 2025 9:56 am

Yes, excuse me but your answer has come when i realize that i was using an old version of your library.
So i downloaded your latest version (11.10.3) but unfortunately with the same error.
Thank you.

mgasperi
 
Posts: 5
Joined: Thu Jul 27, 2023 2:50 pm

Thu Nov 13, 2025 3:35 am

Hello

Thank you for your testing feedback.
The 'gary.pfx' certificate in our example uses the SHA-1 algorithm. What is your certificate algorithm? If it is SHA-256 type or other, currently our Java product has some problems parsing such certificates. We will optimize and improve this part, its' task number is SPIREPDF-7829. You can share the algorithm type of your certificate with us, so that our optimization can cover the types you use. Thank you in advance.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1533
Joined: Wed Apr 25, 2018 3:20 am

Thu Nov 13, 2025 9:29 am

Hello,

Yes, it's a SHA-256 algorithm. I could give you my certificate, but you can create a similar one easily with openssl for testing purposes.

Thank you.

mgasperi
 
Posts: 5
Joined: Thu Jul 27, 2023 2:50 pm

Thu Nov 13, 2025 10:18 am

Hello

Thank you for your feedback.
Yes, it is consistent with the issue we currently know, our Dev team colleagues are working on it. We will notify you once there is any update progress. Thank you for your understanding.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1533
Joined: Wed Apr 25, 2018 3:20 am

Fri Jun 05, 2026 1:35 am

Hello,

Thank you for your patience.
We have released Spire.PDF for Java Version:12.6.1, which adds support for signing with SHA-256/SHA-512 algorithm certificates. Please update and refer to the following sample code for testing.
Code: Select all
    public static void main(String[] args) throws IOException {
        // Create pdf document
        PdfDocument doc = new PdfDocument();
        // Load file from disk
        doc.loadFromFile("Sample.pdf");
        // Load the X509 certificate for signature
        PdfPKCS7Formatter formatter = new PdfPKCS7Formatter(new PdfCertificate("gary.pfx", "e-iceblue"), false);
        // Create an instance of PdfOrdinarySignatureMaker using the loaded document and certificate
        PdfOrdinarySignatureMaker signatureMaker = new PdfOrdinarySignatureMaker(doc, formatter);
        // Create an instance of PdfCustomSignatureAppearance as the appearance for the signature
        IPdfSignatureAppearance signatureAppearance = new PdfCustomSignatureAppearance();
        // Make the signature with a specified name and the custom appearance
        signatureMaker.makeSignature("Signature", signatureAppearance);
        // Iterate through all hash algorithm types
        for (HashAlgorithmType hashAlg : HashAlgorithmType.values()) {
            // Skip SM3 (case-insensitive)
            if ("SM3".equalsIgnoreCase(hashAlg.name())) {
                continue;
            }
            try {
                // Set the current hash algorithm
                formatter.getProperties().setHashAlgorithm(hashAlg);
                String filePath = "AddImageSignature_" + hashAlg.name() + ".pdf";
                doc.saveToFile(filePath, FileFormat.PDF);

            } catch (Exception ex) {
                System.out.println( ex.getMessage());
            }
        }
        // Close the document
        doc.close();
    }
    // Custom signature appearance implementation
    public static class PdfCustomSignatureAppearance implements IPdfSignatureAppearance {
        @Override
        public void generate(PdfCanvas pdfCanvas) {
            // Set font size
            int fontSize = 10;
            // Create Arial font
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", Font.PLAIN, fontSize), true);
            // Set line height
            float lineHeight = fontSize;
            // Draw text string
            pdfCanvas.drawString("AAAAAAAAAAA", font, PdfBrushes.getRed(), new Point.Float(0, 0));
            // Draw image at specified position
            pdfCanvas.drawImage(PdfImage.fromFile("E-iceblue logo.png"), new Point.Float(20, 0));
        }
    }

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1533
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDF