CipherUtil { public static byte[] createRandomArray(int size) { byte[] randomByteArray = new byte[size]; secureRandom.nextBytes(randomByteArray); return randomByteArray; }  static synchronized void init(); static void enableUnlimitedStrength(); static byte[] createRandomArray(int size); static String createRandomAlphabeticString(int size); static SaltedSecretKey createDerivedKey(SecretKey inputKey, byte[] inputSalt, CipherSpec outputCipherSpec); static SaltedSecretKey createDerivedKey(byte[] inputKeyMaterial, byte[] inputSalt, String outputKeyAlgorithm, int outputKeySize); static SecretKey toSecretKey(byte[] secretKeyBytes, String algorithm); static SaltedSecretKey toSaltedSecretKey(byte[] secretKeyBytes, byte[] saltBytes, String algorithm); static SaltedSecretKey createMasterKey(String password); static SaltedSecretKey createMasterKey(String password, byte[] salt); static boolean isEncrypted(File file); static void encrypt(InputStream plaintextInputStream, OutputStream ciphertextOutputStream, List<CipherSpec> cipherSpecs,
			SaltedSecretKey masterKey); static byte[] encrypt(InputStream plaintextInputStream, List<CipherSpec> cipherSuites, SaltedSecretKey masterKey); static byte[] decrypt(InputStream fromInputStream, SaltedSecretKey masterKey); static KeyPair generateRsaKeyPair(); static X509Certificate generateSelfSignedCertificate(String commonName, KeyPair keyPair); static SSLContext createSSLContext(KeyStore keyStore, KeyStore trustStore);  }
@Test public void testCreateRandomArray() throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException { byte[] randomArray1 = CipherUtil.createRandomArray(10); byte[] randomArray2 = CipherUtil.createRandomArray(10); assertEquals(10, randomArray1.length); assertEquals(10, randomArray2.length); assertFalse(Arrays.equals(randomArray1, randomArray2)); }
@Test public void testEncryptLongArrayAes128Gcm() throws Exception { testEncrypt( TestFileUtil.createRandomArray(1024*1024), Arrays.asList(new CipherSpec[] { CipherSpecs.getCipherSpec(CipherSpecs.AES_128_GCM) }) ); }
@Test public void testEncryptLongArrayAes128Twofish128() throws Exception { testEncrypt( TestFileUtil.createRandomArray(1024*1024), Arrays.asList(new CipherSpec[] { CipherSpecs.getCipherSpec(CipherSpecs.AES_128_GCM), CipherSpecs.getCipherSpec(CipherSpecs.TWOFISH_128_GCM) }) ); }
@Test public void testEncryptLongArrayAes258Twofish256UnlimitedStrength() throws Exception { testEncrypt( TestFileUtil.createRandomArray(1024*1024), Arrays.asList(new CipherSpec[] { CipherSpecs.getCipherSpec(CipherSpecs.AES_256_GCM), CipherSpecs.getCipherSpec(CipherSpecs.TWOFISH_256_GCM) }) ); }