private void init(javax.crypto.Cipher cipher, int mode, java.security.Key key,
                      AlgorithmParameterSpec spec, SecureRandom random) throws CryptoException {
        try {
            if (random != null) {
                if (spec != null) {
                    cipher.init(mode, key, spec, random);
                } else {
                    cipher.init(mode, key, random);
                }
            } else {
                if (spec != null) {
                    cipher.init(mode, key, spec);
                } else {
                    cipher.init(mode, key);
                }
            }
        } catch (Exception e) {
            String msg = "Unable to init cipher instance.";
            throw new CryptoException(msg, e);
        }
    }
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