>javac -d bin src/*.java src/my/secret/code/*.java
我把Main.class和MySecretClass.class进行了.加密:
>java -cp bin EncryptedClassLoader -encrypt bin Main my. secret.code.MySecretClass encrypted [Main.class] encrypted [my/secret/code/MySecretClass.class]
>java -cp bin Main Exception in thread "main" java.lang.ClassFormatError: Main (Illegal constant pool type) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:502) at java.security.SecureClassLoader.defineClass (SecureClassLoader.java:123) at java.net.URLClassLoader.defineClass(URLClassLoader.java:250) at java.net.URLClassLoader.access$100(URLClassLoader.java:54) at java.net.URLClassLoader$1.run(URLClassLoader.java:193) at java.security.AccessController.doPRivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:186) at java.lang.ClassLoader.loadClass(ClassLoader.java:299) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265) at java.lang.ClassLoader.loadClass(ClassLoader.java:255) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
>java -cp bin EncryptedClassLoader -run bin Main decrypted [Main] decrypted [my.secret.code.MySecretClass] secret result = 1362768201
... c = defineClass0(name, b, off, len, protectionDomain); //Intercept classes defined by the system loader and its children: if (isAncestor (getSystemClassLoader ().getParent ())) { // Choose your own dump location here [use an absolute pathname]: final File parentDir = new File ("c:/TEMP/classes/"); File dump = new File (parentDir, name.replace ('.', File.separatorChar) + "[" + getClass ().getName () + "@" +Long.toHexString (System.identityHashCode (this)) + "].class");