假如这个CLASS 被我用des加密了,当然我能解密,但解密后的数据怎样加载呢?

解决方案 »

  1.   

    自定义一个DecryptClassLoader,在内存中解密之后加载该class
    楼主去看看关于java类加载机制方面的资料吧。
      

  2.   

    那我解密后,要将解密的数据写入到一个class文件里吗
      

  3.   

    CLASS 用des加密??
    貌似很有意思,怎么实现的,楼主说下啊.
      

  4.   


    不需要,你在自定义的classloader中将class的字节数组修改了即可,这个有一个自定义classloader的例子:
    http://blog.chinaunix.net/u/32945/showart_255326.html
      

  5.   


         public Class findClass(String name)throws ClassNotFoundException
         {
            Class resultClass=null;
            String pathName=name.replace('.','/');
             byte[] data = loadClassData(pathName);
             resultClass=defineClass(name, data, 0, data.length);
            return resultClass;
         }1:这个方法是怎样调用的
    2:defineClass(String name, byte[] b, int off, int len) String name  这个参数是什么,看不懂
      

  6.   

    怎么调用的方法不是在main方法中写了:
         public static void main(String[] args) throws Exception     {        FileClassLoader loader = new FileClassLoader("D:/TestDir/t.jar");        Class objClass = loader.loadClass("com.TestClassLoader");        Class objClass2 = loader.loadClass("com.TestClassLoaderUse");        Object obj = objClass.newInstance();        //通过reflect执行函数..doit(String a);        Method method=objClass.getMethod("doit",new Class[]{String.class});        System.out.println("method doit() return:"+method.invoke(obj,new Object[]{"J"}));        System.out.println(objClass.getName());        System.out.println(objClass.getClassLoader());                     }name就是你的class名称,如com.TestClassLoaderUse,com.x...
      

  7.   

    呵,看明白了String name  原来是类名丫URL url=new URL("jar:file:/"+drive+"!/"+name+".class");
    这样写的还是第一次看到中间的 !号啥意思 是固定写法?
      

  8.   

    当调用loadClass时,loadClass方法内部会调用findClass
      

  9.   

    说实话public Class findClass(String name)
    {}这个方法在哪调用的还是没看到
      

  10.   

    你怎么不查查JDK的文档呢?我给你贴出来算了:
    loadClass
    public Class loadClass(String name)
                    throws ClassNotFoundException
    Loads the class with the specified name. This method searches for classes in the same manner as the loadClass(String, boolean) method. It is invoked by the Java virtual machine to resolve class references. Invoking this method is equivalent to invoking loadClass(name, false). 
    Parameters:
    name - The name of the class 
    Returns:
    The resulting Class object 
    Throws: 
    ClassNotFoundException - If the class was not found--------------------------------------------------------------------------------loadClass
    protected Class loadClass(String name,
                              boolean resolve)
                       throws ClassNotFoundException
    Loads the class with the specified name. The default implementation of this method searches for classes in the following order: Invoke findLoadedClass(String) to check if the class has already been loaded. Invoke the loadClass method on the parent class loader. If the parent is null the class loader built-in to the virtual machine is used, instead. Invoke the findClass(String) method to find the class. If the class was found using the above steps, and the resolve flag is true, this method will then invoke the resolveClass(Class) method on the resulting Class object. Subclasses of ClassLoader are encouraged to override findClass(String), rather than this method. 
    Parameters:
    name - The name of the class
    resolve - If true then resolve the class 
    Returns:
    The resulting Class object 
    Throws: 
    ClassNotFoundException - If the class could not be found
      

  11.   

    我是说 findClass 不是 loadClass