Skip to content

Instantly share code, notes, and snippets.

@KravaDanil
Created December 5, 2016 10:12
Show Gist options
  • Save KravaDanil/8990c00549cfc7a207485945339dcbca to your computer and use it in GitHub Desktop.
Save KravaDanil/8990c00549cfc7a207485945339dcbca to your computer and use it in GitHub Desktop.
private static byte[] encrypt(byte[] key, byte[] input) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(input);
return encrypted;
}
private static byte[] decrypt(byte[] key, byte[] encrypted) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(key, "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