Skip to content

Instantly share code, notes, and snippets.

@kikoso
Created April 29, 2017 14:23
Show Gist options
  • Save kikoso/b8c3efdcad3f449c4cb8fd41a6df82bc to your computer and use it in GitHub Desktop.
Save kikoso/b8c3efdcad3f449c4cb8fd41a6df82bc to your computer and use it in GitHub Desktop.
private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
}
private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decrypted = cipher.doFinal(encrypted);
return decrypted;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment