package com.xdrop.passlock.crypto;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import java.security.AlgorithmParameters;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidParameterSpecException;

public class AESEncrypt {

    private static final Logger LOG = LoggerFactory.getLogger(AESEncrypt.class);

    private static final String cipherType = "AES/CBC/PKCS5Padding";


    /**
     * Encrypts a given payload using the secret key provided.
     *
     * @param payload The byte array of data to be encrypted
     * @param key The key with which the data should be encrypted
     * @return The encrypted payload and the IV vector
     * @throws BadPaddingException
     * @throws IllegalBlockSizeException
     */
    public AESOutput encrypt(byte[] payload, SecretKey key) throws BadPaddingException, IllegalBlockSizeException {

        try {

            Cipher cipher = Cipher.getInstance(cipherType);
            cipher.init(Cipher.ENCRYPT_MODE, key);

            AlgorithmParameters params = cipher.getParameters();
            byte[] iv = params.getParameterSpec(IvParameterSpec.class).getIV();

            byte[] output = cipher.doFinal(payload);

            return new AESOutput(output, iv);

        } catch (NoSuchAlgorithmException |
                NoSuchPaddingException |
                InvalidKeyException |
                InvalidParameterSpecException e) {

            LOG.info("Failed to encrypt", e);
            return null;

        }

    }


}

@@ -928,62 +928,8 @@
 key)
- throws BadPaddingException, IllegalBlockSizeException
  %7B%0A%0A
@@ -1417,32 +1417,114 @@
 dKeyException %7C%0A
+                BadPaddingException %7C%0A                IllegalBlockSizeException %7C%0A
                 

Remove catched exceptions