import
javax.crypto.Cipher;
import
javax.crypto.SecretKey;
import
javax.crypto.spec.SecretKeySpec;
public
class
EncryptionUtils {
private static final String AES_ALGORITHM
=
"AES"
;
public static byte[] encrypt(byte[] data, byte[] key) throws Exception {
SecretKey secretKey
=
new SecretKeySpec(key, AES_ALGORITHM);
Cipher cipher
=
Cipher.getInstance(AES_ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
return
cipher.doFinal(data);
}
public static byte[] decrypt(byte[] encryptedData, byte[] key) throws Exception {
SecretKey secretKey
=
new SecretKeySpec(key, AES_ALGORITHM);
Cipher cipher
=
Cipher.getInstance(AES_ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, secretKey);
return
cipher.doFinal(encryptedData);
}
}