Created
April 21, 2012 15:59
-
-
Save bricef/2437994 to your computer and use it in GitHub Desktop.
Encrypt with AES using Java.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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