0

I am trying to use bouncy castle in Java but keep getting this error:

packacge org.bouncycastle.jce.provider does not exist

I'm using intellij, I have the bouncycastle jar in my CLASSPATH environment variable. I did set up bouncy castle and had it working, but seem to have logged on today and have this error.

The code where I am trying to use bouncy castle looks like this:

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jce.ECNamedCurveTable;
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
import org.bouncycastle.jce.spec.ECNamedCurveSpec;

//in main
Security.addProvider(new BouncyCastleProvider());

String providerName = "BC";
Provider provider = Security.getProvider(providerName);

KeyFactory key = KeyFactory.getInstance("EC");
ECNamedCurveParameterSpec paramSpec = ECNamedCurveTable.getParameterSpec("secp256r1");
ECParameterSpec params = new ECNamedCurveSpec("secp256r1", paramSpec.getCurve(), paramSpec.getG(), paramSpec.getN(), paramSpec.getH());

LozCodes
  • 109
  • 8
  • What is your classpath? The provider is in the bcprov jar, which is also where the other classes you use are located. – ewramner May 17 '22 at 13:28
  • That looks incorrect. Try `C:\Program Files\Java\jre\lib\ext\bcprov.jar`. Also, you probably should be putting stuff in the `lib\ext` directory. The Java "extensions" directory is no longer supported after Java 8, and it was never a good idea. – Stephen C May 17 '22 at 13:49
  • And if you are getting compilation errors in Intellij, look at the Intellij documentation to see how you are supposed yo configure the classpath *inside Intellij. Or read https://stackoverflow.com/questions/1051640/ – Stephen C May 17 '22 at 13:53
  • @StephenC My class path is C:\Program Files\Java\jre1.8.0_271\lib\ext\bcprov-jdk18on-171.jar – LozCodes May 17 '22 at 13:55
  • Ah ... you've changed your story. You previously said it was `C:\Program Files\Java\jre\lib\ext\bcprov`. Anyway, Intellij won't be looking at the CLASSPATH variable at all. See my second comment. – Stephen C May 17 '22 at 13:57
  • @StephenC Sorry - I wasn't looking in the right place, my bad! I've check that other question and added a module in Intellij, that seems to have solved my problem - thank you! – LozCodes May 17 '22 at 13:59

0 Answers0