bouncy castle DefaultSignatureAlgorithmIdentifierFinder NoSuchFieldError: gostR3410_94

bouncy castle DefaultSignatureAlgorithmIdentifierFinder NoSuchFieldError: gostR3410_94

我正在使用 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();

此问题的解决方案是使用早期版本的 Bouncy Castle Provider:bcprov-jdk15on-1.54.jar。此 jar 与 bcpkix-jdk15on-1.54.jar 兼容。较新的 jar 导致 CryptoProObjectIdentifiers 对象标识符不匹配。