首先编写一个加密算法,对文件进行加密
package javatribe.fts.generic;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class MyClassLoader {
/**
* @param args
*/
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
//源文件路径名
String srcPath=args[0];
//目标路径名
String destDir=args[1];
//获得输入流
FileInputStream fis=new FileInputStream(srcPath);
//获得目标的文件名,即加密之后的文件名称
String destFileName=srcPath.substring(srcPath.lastIndexOf('\\')+1);
//目标的路径,即加密之后文件传输到的路径
String destPath=destDir+'\\'+destFileName;
//输出流
FileOutputStream fos=new FileOutputStream(destPath);
//进行加密运算
cypher(fis,fos);
fis.close();
fos.close();
}
private static void cypher(InputStream ips,OutputStream ops) throws Exception{
int b=-1;
while((b=ips.read())!=-1){
ops.write(b ^ 0xff);
}
}
}
对文件ClassLoaderAttachment进行加密
package javatribe.fts.generic;
import java.util.Date;
public class ClassLoaderAttachment extends Date {
public String toString(){
return "Hello,World";
}
}
进行加密后的类系统自带的类加载是无法读取的,会提示错误
自己编写的加密工具需要对class文件进行解密后系统自带的编译工具才能够解释运行,接下来可以自己编写一个简单的类加载器对加密后的文件进行解密加载