EncryptClasses { static void encrypt(String... clazz) throws Exception { String keyFilename = clazz[0]; SecureRandom sr = new SecureRandom(); byte[] rawKey = FileUtils.readFile(keyFilename); assert rawKey != null; DESKeySpec dks = new DESKeySpec(rawKey); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM); SecretKey key = keyFactory.generateSecret(dks); Cipher cipher = Cipher.getInstance(ALGORITHM); cipher.init(Cipher.ENCRYPT_MODE, key, sr); String filename; byte[] classData, encryptedClassData; for (int i = 1; i < clazz.length; ++i) { filename = clazz[i]; classData = FileUtils.readFile(filename); assert classData != null; encryptedClassData = cipher.doFinal(classData); FileUtils.writeFile(filename, encryptedClassData); _log.debug("Encrypted {}", filename); } }    }
@Test @Ignore public void encrypt() throws Exception { EncryptClasses.encrypt(DirUtils.RESOURCES_PATH.concat("security/key.data"), CLASSES_PATH.concat("UnsafeApp.class"), CLASSES_PATH.concat("UnsafeClass.class")); }