Code example for IvParameterSpec

        String ciphertext = "";
        SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
        Cipher cipher = Cipher.getInstance(CRYPTO_SPEC);
        IvParameterSpec ivSpec = new IvParameterSpec(iv);
        cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
        byte[] ciphertextBytes = cipher.doFinal(cleartext.getBytes());
        ciphertext = new String(Base64.encode(ciphertextBytes, Base64.DEFAULT));
        return ciphertext;
     * Encrypts the provided byte array. 
     * @param cleartext The text to be encrypted. 
     * @param key The AES key to use for encrypting. 
     * @param iv The initialisation vector to use for encrypting. 
     * @return A byte array representing the encrypted text. 
Stop searching for code, let great code find you!  Add Codota to your java IDE