Ich versuche, digitale Signaturdaten aus signierten PDF mit iTextPDF in Java zu extrahieren. Mein Code ist:iTextPDF 5.5.0 BouncyCastle Abhängigkeitsproblem
PdfReader reader = new PdfReader(is);
AcroFields af = reader.getAcroFields();
ArrayList<String> names = af.getSignatureNames();
if(names == null || names.isEmpty()) return null;
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
ArrayList<Map<QName, Serializable>> aspects = new ArrayList<Map<QName, Serializable>>();
for (String name : names) {
System.out.println("Signature name: " + name);
System.out.println("Signature covers whole document: " + af.signatureCoversWholeDocument(name));
System.out.println("Document revision: " + af.getRevision(name) + " of " + af.getTotalRevisions());
PdfPKCS7 pk = af.verifySignature(name);
X509Certificate certificate = pk.getSigningCertificate();
Map<QName, Serializable> aspectSignatureProperties = new HashMap<QName, Serializable>();
aspectSignatureProperties.put(SignModel.PROP_CERTIFICATE_PRINCIPAL, certificate.getSubjectX500Principal().toString());
aspectSignatureProperties.put(SignModel.PROP_CERTIFICATE_SERIAL_NUMBER, certificate.getSerialNumber().toString());
aspectSignatureProperties.put(SignModel.PROP_CERTIFICATE_NOT_AFTER, certificate.getNotAfter());
aspectSignatureProperties.put(SignModel.PROP_CERTIFICATE_ISSUER, certificate.getIssuerX500Principal().toString());
aspects.add(aspectSignatureProperties);
}
jedoch bei PdfPKCS7 pk = af.verifySignature(name);
ich diese Ausnahme erhalten:
Caused by: java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1ObjectIdentifier
at com.itextpdf.text.pdf.AcroFields.verifySignature(AcroFields.java:2349)
at com.itextpdf.text.pdf.AcroFields.verifySignature(AcroFields.java:2302)
at es.keensoft.alfresco.behaviour.CustomBehaviour.getDigitalSignatures(CustomBehaviour.java:133)
at es.keensoft.alfresco.behaviour.CustomBehaviour.onCreateNode(CustomBehaviour.java:78)
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.alfresco.repo.policy.JavaBehaviour$JavaMethodInvocationHandler.invoke(JavaBehaviour.java:174)
at com.sun.proxy.$Proxy54.onCreateNode(Unknown Source)
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.alfresco.repo.policy.TransactionBehaviourQueue.execute(TransactionBehaviourQueue.java:245)
... 41 more
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.asn1.ASN1ObjectIdentifier at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) ... 56 more
Ich versuchte BouncyCastle Abhängigkeiten zu schließen, aber dann bekomme ich:
Signer information does not match
Irgendwelche Ideen? Dank
EDIT:
Ich verwende Maven mit diesen Abhängigkeiten:
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.49</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.49</version>
</dependency>
und ich erhalte den folgenden Fehler:
java.lang.SecurityException: class "org.bouncycastle.asn1.ASN1ObjectIdentifier"'s signer information does not match signer information of other classes in the same package
Welche Version von BouncyCastle verwenden Sie? Wenn Sie Maven verwenden, führen Sie diesen Befehl aus und fügen Sie die Ausgabe Ihrer Frage hinzu: 'mvn dependency: tree -Dverbose' –
@AmedeeVanGasse Fertig. Entschuldigung, das habe ich vorher nicht verstanden. –
@AmedeeVanGasse alles? –