0

I have ran into a problem concerning classloaders in Java.

For some reason I have encrypted a class with AES, when my program starts it decrypts the class using a key provided by a web service. I have written my own classloader which calls super.defineClass(String, byte[], int, int) which works 100%

But when I create a thread (lets say swing) and use the class I decrypted previously it throws an exception where the magic number is wrong which is understandable (compilation version messed up due to classloading). However the class works perfectly fine when I do not use it in a thread which is not an option.

How would I fix this?

August
  • 12,410
  • 3
  • 35
  • 51
  • Have you tried the solution here : http://stackoverflow.com/questions/2822004/change-classloader Maybe it can help you. – JFPicard Mar 11 '15 at 20:54
  • 3
    It has nothing to do with threads. If you load the same class with two different class loaders you have, in essence, two different classes. – Hot Licks Mar 11 '15 at 21:23
  • Are you getting the key in a seperate thread properly? Have you tried to dump the decrypted bytes to verify they are the same? If the magic number at the beginning of the classfile is wrong, that means it's probably garbage data. – Antimony Mar 12 '15 at 03:03
  • Without seeing actual code, that’s guessworking. – Holger Mar 12 '15 at 10:06

0 Answers0