AES { public byte[] encrypt(byte[] value) throws Exception { return aes(Cipher.ENCRYPT_MODE, key, value, 0, value.length); } private  AES(); byte[] encrypt(byte[] value); byte[] decrypt(byte[] value); byte[] encrypt(byte[] value, int start, int length); byte[] decrypt(byte[] value, int start, int length); @Override String toString(); static final BlockCipherMode DEFAULT_CIPHER_MODE; static final Padding DEFAULT_PADDING; static final byte[] DEFAULT_IV; }
@Test public void testSimpleEncrypt() { try { AES aes = new AES.Builder().cipherMode(AES.BlockCipherMode.CBC) .padding(AES.Padding.PKCS5) .key(SHA256.hash(TestConstants.key.getBytes())).build(); byte[] result = aes.encrypt(TestConstants.msg.getBytes()); String base64Result = Base64.encodeToString(result); Assert.assertEquals(base64Result, TestConstants.encryptedBase64Msg); } catch (Exception e) { e.printStackTrace(); } }