Skip to content

Instantly share code, notes, and snippets.

@bricef
Created April 21, 2012 15:59
Show Gist options
  • Save bricef/2437994 to your computer and use it in GitHub Desktop.
Save bricef/2437994 to your computer and use it in GitHub Desktop.
Encrypt with AES using Java.
public static byte[] encrypt(String plainText, String encryptionKey, String IV) throws Exception {
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE");
SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES");
cipher.init(Cipher.ENCRYPT_MODE, key,new IvParameterSpec(IV.getBytes("UTF-8")));
return cipher.doFinal(plainText.getBytes("UTF-8"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment