您的位置:首页 > 编程语言 > Java开发

java 核心代码加密思路

2017-11-24 18:20 429 查看
1.通道加密算法将jar包加密

2.获取加密jar包的文件流,通过解密算法将流文件解密

3.通过org.xeustechnologies.jcl工具包动态加载类

实例代码:

InputStream in = JDSecurityLoader.class.getResourceAsStream("/jar.hex");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buff = new byte[300000];

while(in.available() > 0) {
int readNumber = in.read(buff);
bos.write(buff, 0, readNumber);
}

in.close();
bos.flush();
bos.close();
byte[] encrytedClass = bos.toByteArray();
byte[] key = Base64.decodeBase64("key");
SecretKey JCEkey = new SecretKeySpec(key, "AES");
IvParameterSpec ivParameterSpec = new IvParameterSpec(key);
Cipher cipherDec = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipherDec.init(2, JCEkey, ivParameterSpec);
byte[] origClass = cipherDec.doFinal(encrytedClass);
ByteArrayInputStream bin = new ByteArrayInputStream(origClass);
this.jcl = new JarClassLoader();
this.jcl.add(bin);
this.factory = JclObjectFactory.getInstance();
this.isInit = true;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: