public static Cipher createAesCipher(Key key, int mode) throws Exception
    {
        // Use password key as seed for IV (must be 16 bytes)
        MessageDigest d = getMD5Digest();
        d.update(key.getEncoded());
        byte[] iv = d.digest();

        AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv);
        Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");        // CBC faster than CFB8/NoPadding (but file length changes)
        cipher.init(mode, key, paramSpec);
        return cipher;
    }
public static Cipher createAesCipher ( Key key , int mode ) throws Exception { MessageDigest d = getMD5Digest ( ) ; d . update ( key . getEncoded ( ) ) ; byte [ ] iv = d . digest ( ) ; AlgorithmParameterSpec paramSpec = new IvParameterSpec ( iv ) ; Cipher cipher = Cipher . getInstance ( "AES/CBC/PKCS5Padding" ) ; cipher . init ( mode , key , paramSpec ) ; return cipher ; }
Creates a Cipher from the passed in key, using the passed in mode.
@param key  SecretKeySpec
@param mode Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODE
@return Cipher instance created with the passed in key and mode.