BouncyCastle in Java
14,825
Two problems:
- The class is named
X509EncodedKeySpec
notx509EncodedKeySpecs
. Fix yourimport
statement. - Make sure the BouncyCastle JAR is on the classpath when you compile and run your code.
Comments
-
suraj almost 2 years
I have used the following cod in my program to convert byte to public key
Security.addProvider(new BouncyCastleProvider()); X509EncodedKeySpec x509keyspec=new X509EncodedKeySpec(b); KeyFactory keyfact=KeyFactory.getInstance("RSA","BC"); Key pubkey=keyfact.generatePublic(x509keyspec);
I have imported "import org.bouncycastle.jce.provider.BouncyCastleProvider;",.
I have added Bouncycastle.jar file into my jre7/lib/ext folder and made changes in javasecurity file by adding following line
security.provider.11=org.bouncycastle.jce.provider.BouncyCastleProvider
When i compile code i m getting following errorReverse.java:14: error: cannot find symbol import java.security.spec.x509EncodedKeySpecs; ^ symbol: class x509EncodedKeySpecs location: package java.security.spec Reverse.java:16: error: package org.bouncycastle.jce.provider does not exist import org.bouncycastle.jce.provider.BouncyCastleProvider; Reverse.java:49: error: cannot find symbol Security.addProvider(new BouncyCastleProvider()); ^ symbol: class BouncyCastleProvider location: class Reverse
-
suraj over 12 yearsBouncyCastle.JAR is in c:program files/jre7/lib/ext folder. Still i am getting errors
-
Jesper over 12 yearsPutting it in the lib/ext folder of the JRE doesn't mean that the Java compiler will automatically pick it up when compiling your program. Make sure it is in the classpath when you compile your program.
-
suraj over 12 yearsReverse.java:49: error: cannot find symbol Security.addProvider(new BouncyCastleProvider());
-
suraj over 12 yearsIn Environment Variable i put a variable called classpath and assigned it path c:program files/jre7/lib/ext/bouncycastle. Still the error is not rectified
-
Jesper over 12 yearsIf you literally put
c:program files/jre7/lib/ext/bouncycastle
in theCLASSPATH
, then that's wrong. Add the JAR file to theCLASSPATH
correctly. Use the-cp
switch on the command line. For example:javac -cp "C:\Program Files\jre7\lib\ext\bouncycastle.jar" Reverse.java
-
suraj over 12 yearsC:\Program Files\Java\jdk1.7.0_02\bin>java -cp . Reverse Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/ provider/BouncyCastleProvider at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2442) at java.lang.Class.getMethod0(Class.java:2685) at java.lang.Class.getMethod(Class.java:1620) at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:488) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:480)
-
suraj over 12 yearsI m using jdk 1.7 and i checked out and found out der is no bouncycastle for jdk1.7. Is dat a issue?
-
Jesper over 12 yearsAlso put the JAR in the classpath when running the application:
java -cp "C:\Program Files\jre7\lib\ext\bouncycastle.jar;." Reverse