6

I want to encrypt a string, but the standard Java libraries are too complicated for me.

So I turned to Jasypt labriry. It's pretty simple to use and understan. However when I import the library to Eclipse 3.6 and when I try encrypt a string like "Hello" with the password "123", it always comes up with an error. I'm not sure what I'mm doing wrong but I think it also happens when I use other libraries in Eclipse.

Source:

import org.jasypt.util.text.BasicTextEncryptor;

public class Main {

    static BasicTextEncryptor textEncryptor = new BasicTextEncryptor();

    public static void main(String[] args) {
        System.out.println("Hello World");
        textEncryptor.setPassword("123");
        System.out.println(textEncryptor.encrypt("Hello World"));
    }
}

The error message:

java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClassCond(Unknown Source)
 at java.lang.ClassLoader.defineClass(Unknown Source)
 at java.security.SecureClassLoader.defineClass(Unknown Source)
 at java.net.URLClassLoader.defineClass(Unknown Source)
 at java.net.URLClassLoader.access$000(Unknown Source)
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at org.jasypt.util.text.BasicTextEncryptor.<init>(BasicTextEncryptor.java:67)
 at eMain.<clinit>(eMain.java:4)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 ... 14 more
informatik01
  • 15,174
  • 9
  • 67
  • 100
Tian
  • 2,143
  • 5
  • 16
  • 10

1 Answers1

4

The library you imported depends on another library containing org/apache/commons/lang/exception/NestableRuntimeException. This is located in the Apache Commons Lang library.

In fact, if you downloaded JASYPT from http://sourceforge.net/projects/jasypt/files/ you'll get a zip file containing a lib-folder with these files:

  • commons-codec-1.1.jar
  • commons-lang-2.1.jar
  • jasypt-1.6.jar

You should include all of these in your project.

I tried it and your little sample program works fine (and prints the following)

Hello World
v09l9j/BIeSoMkQXc2CY0VIJLlLAQTYq

aioobe
  • 383,660
  • 99
  • 774
  • 796
  • do you have any idea how to implement it on hibernate as well? – J888 Oct 25 '13 at 04:35
  • That question is kind of vague. Perhaps you should have a look at user types. I suggest you post a new question regarding this. – aioobe Oct 25 '13 at 08:05