Created
April 30, 2016 15:34
-
-
Save Porama6400/5e911d326f6785efa5cee707433fde95 to your computer and use it in GitHub Desktop.
Make your life easier with AES Encryption :) by Porama6400
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
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