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;