有人可以帮我这个例外吗?这是否意味着我必须在Java版本1.5上运行keytool?
我以前有工作,但是现在我明白了。
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)
由以下原因引起:java.lang.SecurityException:类“ org.bouncycastle.asn1.ASN1ObjectIdentifier”的签名者信息与同一包中其他类的签名者信息不匹配。
这是我的代码:
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);
}
这是我的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>
最佳答案
请检查您的Maven依赖树。您的pom请求bc版本1.5.2,但是根据http://mvnrepository.com/artifact/com.itextpdf/itextpdf/5.5.6,itext期望版本1.49。从pom中删除两个bc元素。