• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Complie time using custom classloader for decryption.

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to decrypt several class during compile time, but my custom classloader could load everything except my encrypted classes.

Here is my sample code and how I test it.

#EncryptedClassLoader will print out the class name it trying to load, for example: "load class: java.lang.System"

1. Compile Test.java file and have it encrypted, make it into a jar file - test.jar.
2. Compile Test1.java file and try to run Test1.class with encrypted Test.class file using :
C:\lib>java -Djava.system.class.loader=EncryptedClassLoader -classpath c:\lib;c:\lib\tools.jar;c:\lib\test.jar Test1

Gives the output:
load class: java.lang.System
load class: java.nio.charset.Charset
load class: java.lang.String
load class: Test1
load class: Test
load class: sun.security.provider.Sun
load class: sun.security.rsa.SunRsaSign
load class: com.sun.net.ssl.internal.ssl.Provider
load class: com.sun.crypto.provider.SunJCE
load class: java.lang.Object
load class: java.io.PrintStream

So now I'm sure there's no problem with my EncryptedClassLoader

3. Try to compile Test1.java with the encrypted Test.class in test.jar(These's no Test.java file in the same folder) by using:

C:\lib>javac -J-Djava.system.class.loader=EncryptedClassLoader -J-classpath -J.;c:\lib;c:\lib\tools.jar;c:\lib\test.jar Test1.java

Give the output:
.............. (loading several system classes)
load class: com.sun.tools.javac.util.Position
Test1.java:4: cannot find symbol
symbol: class Test
public class Test1 extends Test{
load class: java.lang.Long
load class: java.io.DataInputStream
load class: com.sun.tools.javac.jvm.ClassReader$AnnotationCompleter
load class: com.sun.tools.javac.jvm.ClassReader$AnnotationDeproxy
load class: com.sun.tools.javac.jvm.ClassReader$ProxyVisitor
load class: com.sun.tools.javac.code.Types$SubstFcn
load class: com.sun.tools.javac.code.BoundKind
load class: java.lang.StringBuffer
Test1.java:12: cannot find symbol
symbol : method hello()
location: class Test1
new Test1().hello();
2 errors
---> from the output I found that Test.class never visited/loaded by my EncryptedClassLoader

Though I set EncryptedClassLoader as the default system classloader but it seems to load everything except my encrypted class.

Does anyone know why it works like this??

Thank you in advanced,

[ Edited to use code tags - Paul Sturrock ]
[ December 15, 2006: Message edited by: Paul Sturrock ]
He's giving us the slip! Quick! Grab this tiny ad!
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic