BouncyCastle signature creation java.lang.NoSuchFieldError: xmss_SHA256ph
BouncyCastle signature creation java.lang.NoSuchFieldError: xmss_SHA256ph
我正在尝试创建如下所示的签名,但出现此错误:
java.lang.NoSuchFieldError: xmss_SHA256ph
我正在使用 bcprov-jdk15on 和 bcpkix-jdk15on 版本 1.64 和 Java 8. 我尝试了各种签名算法,最新的是 SHA1WITHRSA。我也试过 SHA256WITHRSA 和 SHA256withECDSA。
你知道我为什么会收到这个错误吗?谢谢
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner sha1Signer = new JcaContentSignerBuilder(getSignatureAlgorithm()).build(key);
gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new
JcaDigestCalculatorProviderBuilder().build()).build(sha1Signer, cert));
gen.addCertificates(new JcaCertStore(chain));
CMSTypedDataInputStream msg = new CMSTypedDataInputStream(content);
CMSSignedData signedData = gen.generate(msg, false);
signatureBytes = signedData.getEncoded();
堆栈跟踪
java.lang.NoSuchFieldError: xmss_SHA256ph
at org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder.<clinit>(Unknown Source) ~[bcpkix-jdk15on-1.64.jar:1.64.00.0]
at org.bouncycastle.operator.jcajce.JcaContentSignerBuilder.<init>(Unknown Source) ~[bcpkix-jdk15on-1.64.jar:1.64.00.0]
at com.trovare.document.pki.Signer.sign(Signer.java:162) ~[classes/:na]
at org.apache.pdfbox.pdfwriter.COSWriter.doWriteSignature(COSWriter.java:744) ~[pdfbox-2.0.19.jar:2.0.19]
at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1150) ~[pdfbox-2.0.19.jar:2.0.19]
at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:452) ~[pdfbox-2.0.19.jar:2.0.19]
at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1386) ~[pdfbox-2.0.19.jar:2.0.19]
at org.apache.pdfbox.pdmodel.PDDocument.saveIncremental(PDDocument.java:1392) ~[pdfbox-2.0.19.jar:2.0.19]
at com.trovare.document.pdf.PdfDcoumentSigner.sign(PdfDcoumentSigner.java:167) ~[classes/:na]
at com.trovare.document.DocumentEncryptorApplication.run(DocumentEncryptorApplication.java:62) [classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:784) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:768) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at com.trovare.document.DocumentEncryptorApplication.main(DocumentEncryptorApplication.java:48) [classes/:na]
我使用 java 密钥工具为我测试的每个算法创建了一个新的密钥库和密钥。像这样,例如:
keytool -genkey -alias docsigner -keyalg RSA -keysize 2048 -sigalg SHA256withRSA -validity 3650 -keystore keystore.jks
因此,对于遇到此问题的任何其他人,我的问题已通过将 bouncycastle 的版本更改为 1.60 得到修复。
我应该指出,我尝试了以下版本:1.63、1.62 和 1.61 以及 none 的有效版本。这就是我的 pom 现在的样子(或者它的一部分)
<properties>
<java.version>1.8</java.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
<bouncycastle.version>1.60</bouncycastle.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
...
<dependencies>
我遇到了这个问题,但对“只使用旧版本”的现有答案不满意!
就我而言,我一直在管理以下依赖项:
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.68</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.68</version>
</dependency>
经过一些代码检查并查看依赖层次结构后,我看到另一个不同步的 bouncycastle 依赖被拉入,即:
[INFO] +- org.springframework.security.extensions:spring-security-saml2-core:jar:1.0.10.RELEASE:compile
[INFO] | +- com.narupley:not-going-to-be-commons-ssl:jar:0.3.20:compile
[INFO] | | +- org.bouncycastle:bcprov-ext-jdk15on:jar:1.60:compile
管理附加依赖项以与其他 bouncycastle 依赖项保持一致为我解决了这个问题,即我在我的 POM 中向 dependencyManagement 添加了以下块:
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-ext-jdk15on</artifactId>
<version>1.68</version>
</dependency>
我正在尝试创建如下所示的签名,但出现此错误:
java.lang.NoSuchFieldError: xmss_SHA256ph
我正在使用 bcprov-jdk15on 和 bcpkix-jdk15on 版本 1.64 和 Java 8. 我尝试了各种签名算法,最新的是 SHA1WITHRSA。我也试过 SHA256WITHRSA 和 SHA256withECDSA。
你知道我为什么会收到这个错误吗?谢谢
CMSSignedDataGenerator gen = new CMSSignedDataGenerator();
ContentSigner sha1Signer = new JcaContentSignerBuilder(getSignatureAlgorithm()).build(key);
gen.addSignerInfoGenerator(new JcaSignerInfoGeneratorBuilder(new
JcaDigestCalculatorProviderBuilder().build()).build(sha1Signer, cert));
gen.addCertificates(new JcaCertStore(chain));
CMSTypedDataInputStream msg = new CMSTypedDataInputStream(content);
CMSSignedData signedData = gen.generate(msg, false);
signatureBytes = signedData.getEncoded();
堆栈跟踪
java.lang.NoSuchFieldError: xmss_SHA256ph
at org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder.<clinit>(Unknown Source) ~[bcpkix-jdk15on-1.64.jar:1.64.00.0]
at org.bouncycastle.operator.jcajce.JcaContentSignerBuilder.<init>(Unknown Source) ~[bcpkix-jdk15on-1.64.jar:1.64.00.0]
at com.trovare.document.pki.Signer.sign(Signer.java:162) ~[classes/:na]
at org.apache.pdfbox.pdfwriter.COSWriter.doWriteSignature(COSWriter.java:744) ~[pdfbox-2.0.19.jar:2.0.19]
at org.apache.pdfbox.pdfwriter.COSWriter.visitFromDocument(COSWriter.java:1150) ~[pdfbox-2.0.19.jar:2.0.19]
at org.apache.pdfbox.cos.COSDocument.accept(COSDocument.java:452) ~[pdfbox-2.0.19.jar:2.0.19]
at org.apache.pdfbox.pdfwriter.COSWriter.write(COSWriter.java:1386) ~[pdfbox-2.0.19.jar:2.0.19]
at org.apache.pdfbox.pdmodel.PDDocument.saveIncremental(PDDocument.java:1392) ~[pdfbox-2.0.19.jar:2.0.19]
at com.trovare.document.pdf.PdfDcoumentSigner.sign(PdfDcoumentSigner.java:167) ~[classes/:na]
at com.trovare.document.DocumentEncryptorApplication.run(DocumentEncryptorApplication.java:62) [classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:784) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:768) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) [spring-boot-2.2.5.RELEASE.jar:2.2.5.RELEASE]
at com.trovare.document.DocumentEncryptorApplication.main(DocumentEncryptorApplication.java:48) [classes/:na]
我使用 java 密钥工具为我测试的每个算法创建了一个新的密钥库和密钥。像这样,例如:
keytool -genkey -alias docsigner -keyalg RSA -keysize 2048 -sigalg SHA256withRSA -validity 3650 -keystore keystore.jks
因此,对于遇到此问题的任何其他人,我的问题已通过将 bouncycastle 的版本更改为 1.60 得到修复。
我应该指出,我尝试了以下版本:1.63、1.62 和 1.61 以及 none 的有效版本。这就是我的 pom 现在的样子(或者它的一部分)
<properties>
<java.version>1.8</java.version>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
<bouncycastle.version>1.60</bouncycastle.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>${bouncycastle.version}</version>
</dependency>
...
<dependencies>
我遇到了这个问题,但对“只使用旧版本”的现有答案不满意!
就我而言,我一直在管理以下依赖项:
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.68</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.68</version>
</dependency>
经过一些代码检查并查看依赖层次结构后,我看到另一个不同步的 bouncycastle 依赖被拉入,即:
[INFO] +- org.springframework.security.extensions:spring-security-saml2-core:jar:1.0.10.RELEASE:compile
[INFO] | +- com.narupley:not-going-to-be-commons-ssl:jar:0.3.20:compile
[INFO] | | +- org.bouncycastle:bcprov-ext-jdk15on:jar:1.60:compile
管理附加依赖项以与其他 bouncycastle 依赖项保持一致为我解决了这个问题,即我在我的 POM 中向 dependencyManagement 添加了以下块:
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-ext-jdk15on</artifactId>
<version>1.68</version>
</dependency>