gpt4 book ai didi

java - 类 "org.bouncycaSTLe.asn1.ASN1ObjectIdentifier"的签名者信息与同一包中其他类的签名者信息不匹配

转载 作者:行者123 更新时间:2023-11-30 08:10:48 28 4
gpt4 key购买 nike

有人可以帮我解决这个异常(exception)吗?这是否意味着我必须使用 1.5 的 java 版本运行 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)

Caused by: 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 元素。

关于java - 类 "org.bouncycaSTLe.asn1.ASN1ObjectIdentifier"的签名者信息与同一包中其他类的签名者信息不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31506235/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com