Skip to main content

java.lang.NoClassDefFoundError using javax.crypto.spec.SecretKeySpec

6 replies [Last post]
dlindberg
Offline
Joined: 2008-12-18
Points: 0

The following code works when i run it under the emulator, but when i install the midlet on my Windows Mobile 6.1 device, it throws the NoClassDefFoundError. Obviously i need to include a jar so it get's deployed with the midlet. I don't know which one. i'm currently including satsa-crypto.jar. I'm using the WTK2.5.2_01, eclipse (windows vista dev env). what else do i need?

the line in bold causes the exception, if i remove it, the "In encrypt8" message is displayed.

private static byte[] encrypt(String xml, MessageSpeak ms)
{
byte[] output = null;

try
{
int currentLen = xml.length();
String s1 = "\0\0\0\0\0\0\0\0";
// make sure the input to the cipher has a length divisible by the block size
if (currentLen % 8 > 0)
{
String padding = new String(s1.getBytes(), 0, 8 - (currentLen % 8));
xml += padding;
}

// encrypt the XML stream using 3DES
byte [] b = Key.getBytes("UTF-8");
Key enc = new SecretKeySpec(b, 0, KeyLen, "DESede");
ms.error("In encrypt8");
}
catch (Throwable e)
{
ms.error(e.toString());
//throw new MessageSpeakException(e.getMessage());
}

return output;
}

Thanks in advance,
Dan'l

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dlindberg
Offline
Joined: 2008-12-18
Points: 0

According to the release notes, bouncy castle j2me only works on windows. I'm trying to write some code that will work on multiple enviornments.
Maybe i can't do encryption in j2me in a device independant way yet?

jaywayjohan
Offline
Joined: 2008-06-18
Points: 0

I have used BouncyCaste in Java ME and it works. The problem you have is probably related to some problem in your development environment. I have this problem in Eclipse with MTJ from time to time.

Regards
Johan

sfitzjava
Offline
Joined: 2003-06-15
Points: 0

When you say you are "including the satsa-crypto.jar" do you mean you have selected in the configuration, or that you placed the jar in the projects "lib" directory?
Using the configuration page for the project and selecting the checkbox for satsa-crypto.jar is only making those library classes visible in the emulator, and not adding them to the deployment jar. However you need the WinMo system to have satsa-crypto support using this method. The alternative would be to not check the satsa-crypto support in the WTK settings and add that jar to the projects "lib" directory.

FYI.. In MIDP you do not deploy jars inside the midlet's jar, you must have the library jars extracted and their classes repackaged along with your projects in the final deploy jar. Normally the WTK does this for you when you package it. But to verify you can to a:
jar -tvf .jar
and you should see the class files from the satsa-crypto along side your classes.

-Shawn

dlindberg
Offline
Joined: 2008-12-18
Points: 0

When i say "including the satsa-crypto.jar" i mean that the contents of that jar file are included in my midletjar.jar. jar -tvf verifies this.
Dan'l

sfitzjava
Offline
Joined: 2003-06-15
Points: 0

Oh that's not good. That could mean that the VM you are using does not allow protected packages from being included in the deployment jar. (Which is really how it should be for security reasons).

The JVM classloader (albeit that j2me doesn't have one that you can see there still is one in there), will enforce that classes starting with java., javax., com.sun. can only be loaded from within a protected code repository, and not from the deployed jar.

Which JVM are you using on WinMO?

Maybe you should try bouncycastle's encryption library.

-Shawn

dlindberg
Offline
Joined: 2008-12-18
Points: 0

Thanks for the info. I don't know what JVM i'm using. :-( It's the one that came with my WinMo 6.1 device (i guess i could write some code to figure that out).

You have given me a direction to go. I appreciate the assist.
Dan'l