Can someone help me with this exception? Does this mean that I have to run keytool with the java version of 1.5?
I had it working before, but now I get this.
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.itextpdf.text.pdf.security.CertificateInfo.getSubjectFields(CertificateInfo.java:356)
at com.itextpdf.text.pdf.PdfSignatureAppearance.getAppearance(PdfSignatureAppearance.java:884)
at com.itextpdf.text.pdf.PdfSignatureAppearance.preClose(PdfSignatureAppearance.java:1268)
at com.itextpdf.text.pdf.security.MakeSignature.signDetached(MakeSignature.java:140)
at org.deloitte.cms.efi.controller.signature.SignatureAppearance.sign4(SignatureAppearance.java:181)
at org.deloitte.cms.efi.controller.signature.SignatureAppearance.main(SignatureAppearance.java:208)
Caused by: java.lang.SecurityException: class "org.bouncycastle.asn1.ASN1ObjectIdentifier"'s signer information does not match signer information of other classes in the same package
This is my code:
public void sign4(String src, String name, String dest,
Certificate[] chain, PrivateKey pk,
String digestAlgorithm, String provider, CryptoStandard subfilter,
String reason, String location)
throws GeneralSecurityException, IOException, DocumentException {
// Creating the reader and the stamper
PdfReader reader = new PdfReader(src);
FileOutputStream os = new FileOutputStream(dest);
PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0');
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
//appearance.setReason(reason);
//appearance.setLocation(location);
appearance.setVisibleSignature(name);
// Default text and scaled background image
appearance.setImage(Image.getInstance(IMG));
//appearance.setImageScale(-1);
appearance.setImageScale(0);
// Creating the signature
PrivateKeySignature pks = new PrivateKeySignature(pk, digestAlgorithm, provider);
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain, null, null, null, 0, subfilter);
}
This is my pom.xml
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.6</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.52</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.52</version>
</dependency>
<dependency>
<groupId>org.apache.santuario</groupId>
<artifactId>xmlsec</artifactId>
<version>2.0.4</version>
</dependency>