使用 itext 库签署 PDF 会抛出错误
Signing PDF with itext library throws error
请帮我解决这个问题,这是我第一次在 pdf 上使用签名。我想用证书签署 pdf,但它抛出了我记下的错误,我正在使用 itext-5.0.5 在 netbeans8.2 (JAVA) 中开发桌面应用程序。我已经阅读了一些有关依赖项和版本的内容,我真的不知道如何解决这个问题。感谢您的帮助,如果您能逐步向我解释,那就太好了。谢谢
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/DERObject
at com.itextpdf.text.pdf.PdfSignatureAppearance.getAppearance(PdfSignatureAppearance.java:409)
at com.itextpdf.text.pdf.PdfSignatureAppearance.preClose(PdfSignatureAppearance.java:950)
at com.itextpdf.text.pdf.PdfSignatureAppearance.preClose(PdfSignatureAppearance.java:897)
at com.itextpdf.text.pdf.PdfStamper.close(PdfStamper.java:192)
at clases.Metodos.firmarFactura(Metodos.java:279)
at clases.VendedorHilo.run(VendedorHilo.java:49)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.asn1.DERObject
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
该错误告诉您您的 CLASSPATH 中没有 BouncyCastle。您问题的正常答案是:
Check the POM file of the iText version you are using for the BouncyCastle
version you need. Download that BouncyCastle version, and put it into your
CLASSPATH.
但是,出于某种原因,您使用的是 2010 年 11 月的旧版 iText,而当时的 iText 版本没有 POM 文件。
IMPORTANT: It is a very bad idea in the context of digital signatures! Since 2010, the world of digital signatures has evolved, and this evolution has led to digital signature functionality that is more secure than the functionality that was available in 2010. Please inform your employer that he is asking you to create a type of signatures that is obsolete.
如果您的雇主有意以old-fashioned方式创建签名,您可以查看旧的 iText 存储库,并搜索 iText 5.0.5。您会在 lib directory 中找到几个充气城堡罐。下载 bcmail-jdk14-138.jar、bcprov-jdk14-138.jar 和 bctsp-jdk14-138.jar,并将它们放入您的 CLASSPATH。
IMPORTANT: due to the nature of BouncyCastle, you can expect strange exceptions if you have more than one version of BouncyCastle in your CLASSPATH. That is another reason why you might want to use a more recent version of iText.
注意:如果您将项目设为 Maven 项目,会容易得多。在那种情况下,声明对 iText(最新版本)的依赖就足够了,Maven 会替您完成所有繁重的工作。
请帮我解决这个问题,这是我第一次在 pdf 上使用签名。我想用证书签署 pdf,但它抛出了我记下的错误,我正在使用 itext-5.0.5 在 netbeans8.2 (JAVA) 中开发桌面应用程序。我已经阅读了一些有关依赖项和版本的内容,我真的不知道如何解决这个问题。感谢您的帮助,如果您能逐步向我解释,那就太好了。谢谢
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/DERObject
at com.itextpdf.text.pdf.PdfSignatureAppearance.getAppearance(PdfSignatureAppearance.java:409)
at com.itextpdf.text.pdf.PdfSignatureAppearance.preClose(PdfSignatureAppearance.java:950)
at com.itextpdf.text.pdf.PdfSignatureAppearance.preClose(PdfSignatureAppearance.java:897)
at com.itextpdf.text.pdf.PdfStamper.close(PdfStamper.java:192)
at clases.Metodos.firmarFactura(Metodos.java:279)
at clases.VendedorHilo.run(VendedorHilo.java:49)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.asn1.DERObject
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
该错误告诉您您的 CLASSPATH 中没有 BouncyCastle。您问题的正常答案是:
Check the POM file of the iText version you are using for the BouncyCastle version you need. Download that BouncyCastle version, and put it into your CLASSPATH.
但是,出于某种原因,您使用的是 2010 年 11 月的旧版 iText,而当时的 iText 版本没有 POM 文件。
IMPORTANT: It is a very bad idea in the context of digital signatures! Since 2010, the world of digital signatures has evolved, and this evolution has led to digital signature functionality that is more secure than the functionality that was available in 2010. Please inform your employer that he is asking you to create a type of signatures that is obsolete.
如果您的雇主有意以old-fashioned方式创建签名,您可以查看旧的 iText 存储库,并搜索 iText 5.0.5。您会在 lib directory 中找到几个充气城堡罐。下载 bcmail-jdk14-138.jar、bcprov-jdk14-138.jar 和 bctsp-jdk14-138.jar,并将它们放入您的 CLASSPATH。
IMPORTANT: due to the nature of BouncyCastle, you can expect strange exceptions if you have more than one version of BouncyCastle in your CLASSPATH. That is another reason why you might want to use a more recent version of iText.
注意:如果您将项目设为 Maven 项目,会容易得多。在那种情况下,声明对 iText(最新版本)的依赖就足够了,Maven 会替您完成所有繁重的工作。