private void encrypt(InputStream in, OutputStream out, byte[] key, byte[] iv, boolean prependIv) throws CryptoException {
        if (prependIv && iv != null && iv.length > 0) {
            try {
                //first write the IV:
                out.write(iv);
            } catch (IOException e) {
                throw new CryptoException(e);
            }
        }

        crypt(in, out, key, iv, javax.crypto.Cipher.ENCRYPT_MODE);
    }
Initializes the JDK Cipher with the specified mode and key.  This is primarily a utility method to catch any
potential {@link java.security.InvalidKeyException InvalidKeyException} that might arise.

@param cipher the JDK Cipher to {@link javax.crypto.Cipher#init(int, java.security.Key) init}.
@param mode   the Cipher mode
@param key    the Cipher's Key
@param spec   the JDK AlgorithmParameterSpec for cipher initialization (optional, may be null).
@param random the SecureRandom to use for cipher initialization (optional, may be null).
@throws CryptoException if the key is invalid
src/main/java/org/apache/shiro/crypto/cipher/JcaCipherService.java