private Cipher getCipher ( int mode , byte [ ] iv ) throws SymmetricKeyException { Cipher cipher = null ; try { cipher = getCipherInstance ( "AES/CBC/PKCS7Padding" ) ; if ( cipher == null ) { throw new SymmetricKeyException ( "Cannot get a cipher instance for AES/CBC/PKCS7Padding algorithm" ) ; } SecretKey secret = new SecretKeySpec ( getKey ( ) , "AES" ) ; cipher . init ( mode , secret , new IvParameterSpec ( iv ) ) ; } catch ( InvalidKeyException e ) { throw new SymmetricKeyException ( "Couchbase Lite uses the AES 256-bit key to provide data encryption. " + "Please make sure you have installed 'Java Cryptography Extension (JCE) " + "Unlimited Strength Jurisdiction' Policy provided by Oracle." , e ) ; } catch ( SymmetricKeyException e ) { throw e ; } catch ( Exception e ) { throw new SymmetricKeyException ( e ) ; } return cipher ; }
Get a cipher instance for either encrypt or decrypt mode with an IV header .