Skip to content

Instantly share code, notes, and snippets.

@vivekgidmare
Forked from KravaDanil/cipher_example.java
Created December 8, 2016 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vivekgidmare/396cd43cc4a7e7a587c1ea9a09f01d48 to your computer and use it in GitHub Desktop.
Save vivekgidmare/396cd43cc4a7e7a587c1ea9a09f01d48 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