Question

I have been trying to encrypt some data using BouncyCastle's JCE provider. I'm trying "SHA256withRSA" and I'm getting a "noSuchAlgorithmException". Am I doing something wrong? Can someone help? Thanks

Specifically I'm trying

Signature.getInstance("SHA256withRSA", new BouncyCastleProvider());

As mentioned here - http://www.bouncycastle.org/wiki/display/JA1/X.509+Public+Key+Certificate+and+Certification+Request+Generation

Was it helpful?

Solution

Try this instead:

Signature.getInstance("SHA256withRSA", "BC");

In most of the examples I have seen, the second param has a string being passed in vs. the provider itself.

The getInstance method seems to support having a provider passed in, but perhaps just doing

 new BouncyCastleProvier()

does not construct it properly, resulting in missing algorithms. I suspect by passing the "BC" string instead, it will use the already constructed provider in JCA/JCE.

Ref: http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html#ProviderImplReq

OTHER TIPS

Perhaps this is a matter of selecting a provider.

I see that the standard SunJSSE Provider supports SHA1withRSA, but not SHA256withRSA.

Somewhere in your code do you have something like this:

sigGen = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(privKey);

First add provider

java.security.Security.addProvider(new BouncyCastleProvider());

And then

Signature.getInstance("SHA256withRSA", "BC");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top