views:

36

answers:

1

I want to encrypt a string, but the standard java libraries are too complicated for me. So i turned to JASYPT, Its pretty simple to use and understand, 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 im doing wrong but i think it also happens when i use other libraries in eclipse.

Source

import org.jasypt.util.text.BasicTextEncryptor;

public class eMain {
 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: i.imgur.com/vBe8p.png

Eclipse consle:

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

imported library i.imgur.com/t9AM9.png

+1  A: 

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