Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble integrating BouncyCastle Jar

Okay, I'll say now that I know very little about Java. I was given the Bouncy Castle Jar and told that would contain what I needed to do this assignment. The Jar file is bcprov-jdk15on-147.jar. I'm also doing this on a Unix machine maintained by my school, so I can't go in and play with all of the Java files.

When I compile my class using Javac (specifically I use the command javac -classpath bcprov-jdk15on-147.jar encrypt.java), it compiles without error, but when I go to run the program afterward using the command java encrypt, I get this error message:

Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

My Jar file is located in my main folder with all of my other files, just in case it has to go somewhere special and that's what I didn't do.

When I do java -classpath bcprov-jdk15on-147.jar encrypt this is the error I get:

    Exception in thread "main" java.lang.NoClassDefFoundError: encrypt
Caused by: java.lang.ClassNotFoundException: encrypt
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

Why am I having trouble running the compiled program?

like image 672
user1174511 Avatar asked Apr 13 '12 01:04

user1174511


People also ask

How do you install BouncyCastle?

Installation of Bouncy Castle for use in TomEE itself is done in two steps: Add the Bouncy Castle provider jar to the $JAVA_HOME/jre/lib/ext directory. Create a Bouncy Castle provider entry in the $JAVA_HOME/jre/lib/security/java. security file.

How do I know what version of BouncyCastle I have?

VERSION. UPDATE: new BouncyCastleProvider(). getVersion() is the solution. You could fingerprint known class files with a hash signature and detect that way.

Is bouncy castle part of Java?

BouncyCastle is a Java library that complements the default Java Cryptographic Extension (JCE).


1 Answers

Type this for running the program:

java -classpath bcprov-jdk15on-147.jar:. encrypt

That's because your program also needs to have any libraries it uses as part of the classpath at the time of running, not only at compile time.

like image 52
Óscar López Avatar answered Nov 03 '22 01:11

Óscar López