0

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

Praneeth
  • 309
  • 4
  • 14

3 Answers3

2

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

Jason Dean
  • 9,585
  • 27
  • 36
0

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);
Jason Dean
  • 9,585
  • 27
  • 36
  • I don't. And sorry for my lack of knowledge. I'm not sure of the difference between using a "ContentSigner" built this way and using "Signature" and initializing with private key. Different use cases I suppose? – Praneeth Aug 06 '13 at 16:38
  • The important part I was getting at was the setProvider("BC") part that is telling JCA/JCE to use the BouncyCastle provider. – Jason Dean Aug 06 '13 at 18:57
  • Oh okk. Ya I'm doing that. So you think BouncyCastle jce provider does not have SHA256withRSA in the first place? – Praneeth Aug 06 '13 at 22:49
  • No. It does. I wanted to make sure you were using the BouncyCastle provider. – Jason Dean Aug 07 '13 at 03:29
  • okk ya I'm specifically telling it to use the provider. I don't know what's going wrong. Thanks much for taking time to look into this. – Praneeth Aug 07 '13 at 14:27
0

First add provider

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

And then

Signature.getInstance("SHA256withRSA", "BC");
Ronald Coarite
  • 4,460
  • 27
  • 31