'java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Encodable reading encrypted-pdf-file
I have a "java client" that reads a encrypted-pdf-file that is generated in another different client. The part of the client code where the pdf file is generated:
File destFile = new File("/var/desa/apps/prueba/PdfFile1.pdf");
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
**configuration.setEncrypted(true);
configuration.set128BitKey(true);
configuration.setOwnerPassword("12345");
configuration.setUserPassword("12345");
configuration.setPermissions(PdfWriter.ALLOW_SCREENREADERS);**
exporter.setConfiguration(configuration);
exporter.exportReport();
When I want to read the encrypted-pdf-file in my java client, I´m doing this:
PdfReader reader = new PdfReader("/var/desa/apps/prueba/PdfFile1.pdf", ("12345".getBytes(java.nio.charset.StandardCharsets.UTF_8)));
but it throws a java.lang.ClassNotFoundException:
Exception in thread "main" **java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Encodable**
at com.itextpdf.text.pdf.PdfEncryption.<init>(PdfEncryption.java:149)
at com.itextpdf.text.pdf.PdfReader.readDecryptedDocObj(PdfReader.java:1013)
at com.itextpdf.text.pdf.PdfReader.readDocObj(PdfReader.java:1411)
at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:721)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:181)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:219)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:207)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:197)
at es.tirea.sgpd.pdf.SgpdCartasPdf.modificarCarta(SgpdCartasPdf.java:341)
at es.tirea.sgpd.servicios.impl.SgpdServicioClientes.borradoDireccionCarta(SgpdServicioClientes.java:978)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
at com.sun.proxy.$Proxy21.borradoDireccionCarta(Unknown Source)
at es.tirea.sgpd.clientes.SgpdBorradoDirecciones.ejecuta(SgpdBorradoDirecciones.java:129)
at es.tirea.sgpd.clientes.base.SgpdClienteBase.ejecutaPrincipal(SgpdClienteBase.java:67)
at es.tirea.sgpd.clientes.base.SgpdClienteBase.mainPrincipal(SgpdClienteBase.java:92)
at es.tirea.sgpd.clientes.SgpdBorradoDirecciones.main(SgpdBorradoDirecciones.java:36)
Caused by: **java.lang.ClassNotFoundException: org.bouncycastle.asn1.ASN1Encodable**
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 21 more
I have this in my build-props.xml file:
<property name="lib.textpdf.jar" value="${tirea.3lib}/itextpdf-5.5.13.jar" />
<property name="lib.itext.jar" value="${tirea.3lib}/itext-2.1.7.js6.jar" />
<property name="lib.textxtra.jar" value="${tirea.3lib}/itext-xtra-5.3.1.jar" />
<property name="lib.bcprov.jar" value="${tirea.3lib}/bcprov-jdk15on-156.jar" />
and my build.xml
<!-- ###################################################### -->
<!-- # Classpath # -->
<!-- ###################################################### -->
<path id="project.class.path">
<pathelement path="${java.class.path}"/>
[...]
<pathelement path="${lib.itext.jar}"/>
<pathelement path="${lib.textpdf.jar}"/>
<pathelement path="${lib.textxtra.jar}"/>
<pathelement path="${lib.bcprov.jar}"/>
</path>
It compiles ok and all the libraries are in the correct directories, any idea?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
