GenerateKey { static void generate(String keyFileName) throws Exception { SecureRandom sr = new SecureRandom(); KeyGenerator kg = KeyGenerator.getInstance(SecurityClassLoader.ALGORITHM); kg.init(sr); SecretKey key = kg.generateKey(); FileUtils.writeFile(keyFileName, key.getEncoded()); }    }
@Test public void generate() throws Exception { final String keyFile = DirUtils.RESOURCES_PATH.concat("security/key.data"); GenerateKey.generate(keyFile); new File(keyFile).deleteOnExit(); }