我正在使用BouncyCastle库:bcprov-jdk16-146.jar和bcpkix-jdk15on-1.54.jar。我正在尝试运行以下代码片段,其中最后一行抛出java.lang.NoSuchFieldError: gostR3410_94
我已经尝试过研究这个问题但是没有发现任何东西 - 我不知道为什么我会遇到这个问题? DefaultSignatureAlgorithmIdentifierFinder
的静态初始值设定项出错。使用java8,我也在java.security中添加了bouncycastle作为我的安全提供程序。
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
KeyPair kp = RSAKeyGenerator.generate2();
AsymmetricKeyParameter privateKey =
(AsymmetricKeyParameter) PrivateKeyFactory.createKey(kp.getPrivate().getEncoded());
AsymmetricKeyParameter publicKey =
(AsymmetricKeyParameter) PublicKeyFactory.createKey(kp.getPublic().getEncoded());
X500NameBuilder x500NameBld = new X500NameBuilder(RFC4519Style.INSTANCE);
x500NameBld.addRDN(RFC4519Style.c, "AU");
x500NameBld.addRDN(RFC4519Style.o, "The Legion of the Bouncy Castle");
x500NameBld.addRDN(RFC4519Style.l, "Melbourne");
x500NameBld.addRDN(RFC4519Style.st, "Victoria");
x500NameBld.addRDN(PKCSObjectIdentifiers.pkcs_9_at_emailAddress, "feedback-crypto@bouncycastle.org");
X500Name subject = x500NameBld.build();
PKCS10CertificationRequestBuilder requestBuilder = new PKCS10CertificationRequestBuilder(subject, new SubjectPublicKeyInfo(ASN1Sequence.getInstance(kp.getPublic().getEncoded())));
DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder();
答案 0 :(得分:2)
此问题的解决方案是使用早期版本的Bouncy Castle Provider:bcprov-jdk15on-1.54.jar
。此jar与bcpkix-jdk15on-1.54.jar
兼容。较新的jar导致CryptoProObjectIdentifiers
对象标识符不匹配。