· 9 years ago · Nov 10, 2016, 12:18 PM
1private static byte[] encryptData(ByteArrayOutputStream data, byte[] symmetricKey) throws EncryptionException {
2 try {
3 SecretKey secKey = new SecretKeySpec(symmetricKey, "AES");
4 Cipher cipher = Cipher.getInstance("AES");
5 cipher.init(Cipher.ENCRYPT_MODE, secKey);
6 return cipher.doFinal(data.toByteArray());
7 } catch (NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException |
8 InvalidKeyException |
9 BadPaddingException e) {
10 throw new EncryptionException(e);
11 }
12 }