java 字节码被加密后仍可以反编译
各位大虾,我在网上找了一些加密的资料,然后照着方法对class进行加密,可是加密后虽然不能运行了,但是仍可以使用Jad v1.5.8反编译出来,但是别的类型的文件,比如xml,zip等在加密后却无法打开,不知道是为什么?加密代码如下:
public class AESUtil {
/**
* @param args
* 密码运算参数: args[0]:运算模式,可取值有 encrypt:加密运算 decrypt:解密运算
* args[1]:用户口令,长度固定为16字节(16个英文字符或8个常用汉字)
* args[2]:明文(待进行密码处理的文件)路径,可以为相对或绝对路径
* args[3]:密文(经过密码处理后的文件)路径,可以为相对或绝对路径
*/
public static void main(String[] args) {
int t = 0;
if ("encrypt".equalsIgnoreCase(args[0])) {
t = 1;
} else if ("decrypt".equalsIgnoreCase(args[0])) {
t = 2;
}
String k = args[1];
String p = args[2];
String e = args[3];
try {
c(t, k, p, e);
System.out.println("OK!");
javax.swing.JOptionPane.showMessageDialog(null, "OK!");
} catch (Exception exp) {
exp.printStackTrace();
}
}
/**
* AES密码运算处理
*
* @param t
* 密码运算模式:加密或解密
* @param k
* 密码口令
* @param s
* 密码运算输入文件路径
* @param d
* 密码运算输出文件路径
* @throws Exception
*/
private static final void c(int t, String k, String s, String d)
throws Exception {
java.io.FileInputStream i = new java.io.FileInputStream(s);
java.io.FileOutputStream o = new java.io.FileOutputStream(d);
javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("AES");
c.init(t, new javax.crypto.spec.SecretKeySpec(k.getBytes(), "AES"));
byte[] b = new byte[8192];
int l = i.read(b);
while (l > 0) {
o.write(c.update(b, 0, l));
l = i.read(b);
}
o.write(c.doFinal());
o.flush();
o.close();
i.close();
}
}