Skip to content

Instantly share code, notes, and snippets.

@Porama6400
Created April 30, 2016 15:34
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 Porama6400/5e911d326f6785efa5cee707433fde95 to your computer and use it in GitHub Desktop.
Save Porama6400/5e911d326f6785efa5cee707433fde95 to your computer and use it in GitHub Desktop.
Make your life easier with AES Encryption :) by Porama6400
package me.Porama6400.SOMEWHERE;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
/**
* Created by Porama6400 on 30/4/2016.
*/
public class EasyAES {
byte[] key;
public EasyAES(byte[] key) {
this.key = key;
}
public byte[] encrypt(byte[] input) throws Exception {
Cipher cipher = getCipher(Cipher.ENCRYPT_MODE);
return cipher.doFinal(input);
}
public byte[] decrypt(byte[] input) throws Exception {
Cipher cipher = getCipher(Cipher.DECRYPT_MODE);
return cipher.doFinal(input);
}
private Cipher getCipher(int mode) throws Exception {
String encryption = "AES";
Cipher cipher = Cipher.getInstance(encryption);
SecretKeySpec keyspec = new SecretKeySpec(key, encryption);
cipher.init(mode, keyspec);
return cipher;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment