3
votes

I'm working with BouncyCastle libraries: bcprov-jdk16-146.jar and bcpkix-jdk15on-1.54.jar. And I'm trying to run the following snippet of code, where the last line throws a java.lang.NoSuchFieldError: gostR3410_94 I've tried researching this issue but haven't found anything - I'm not sure why I'm getting this issue? Error occurs in static initializer for DefaultSignatureAlgorithmIdentifierFinder. Using java8 and I've added bouncycastle as my security provider in java.security as well.

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, "[email protected]");

    X500Name subject = x500NameBld.build();

    PKCS10CertificationRequestBuilder requestBuilder = new PKCS10CertificationRequestBuilder(subject, new SubjectPublicKeyInfo(ASN1Sequence.getInstance(kp.getPublic().getEncoded())));

    DefaultSignatureAlgorithmIdentifierFinder sigAlgFinder = new DefaultSignatureAlgorithmIdentifierFinder();
1
From the javadocs: "Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed." Are you doing something funny with reflection and/or dynamic class loading? - President James K. Polk
Nope. It's internal to the bouncy castle classes. But I've figured out my problem: I needed to use bcprov-jdk15on-1.54.jar - the bcprov-jdk16-146.jar is not compatible! - Nena
I'm sorry, I completely missed that in your description. Yes. Post this as an answer please. - President James K. Polk

1 Answers

3
votes

The solution to this problem was to use an earlier version of Bouncy Castle Provider: bcprov-jdk15on-1.54.jar. This jar is compatible with bcpkix-jdk15on-1.54.jar. The newer jar resulted in mismatched CryptoProObjectIdentifiers object identifiers.