Code example for Cipher

Methods: doFinal, init

0
		SecretKeySpec skeySpec = new SecretKeySpec(m_dbKeyData, "AES");  
		m_encryptCipher = Cipher.getInstance("AES/CBC/NoPadding");  
		m_encryptCipher.init(Cipher.ENCRYPT_MODE, skeySpec, paramSpec);
 
		m_decryptCipher = Cipher.getInstance("AES/CBC/NoPadding");  
		m_decryptCipher.init(Cipher.DECRYPT_MODE, skeySpec, paramSpec);
		 
        Logger.T(TAG, "RhoCrypt context initialized for partition: " + szPartition);
    } 
 
    public boolean db_encrypt( String szPartition, ByteBuffer dataIn, ByteBuffer dataOut )
    { 
        try 
        { 
            initContext(szPartition);
 
            dataOut.rewind();
 
            if (m_encryptCipher == null)
                throw new NullPointerException("m_encryptCipher == null");
 
            /* ********************************************************* 
             * Work around Android 4 bug: 
             * http://code.google.com/p/android/issues/detail?id=24327  
             */ 
            ByteBuffer input = ByteBuffer.allocate(dataIn.capacity());
            input.put(dataIn);
            input.rewind();
            /* ******************************************************* */ 
 
            m_encryptCipher.doFinal(input, dataOut);
 
            return true; 
        }catch(Exception exc)
        { 
            Logger.E(TAG, exc);
            return false; 
        } 
    } 
 
    public boolean db_decrypt( String szPartition, ByteBuffer dataIn, ByteBuffer dataOut )
    { 
        try 
        { 
            initContext(szPartition);
             
            dataOut.rewind();
 
            if (m_decryptCipher == null)
                throw new NullPointerException("m_decryptCipher == null");
 
            /* ********************************************************* 
             * Work around Android 4 bug: 
             * http://code.google.com/p/android/issues/detail?id=24327  
             */ 
            ByteBuffer input = ByteBuffer.allocate(dataIn.capacity());
            input.put(dataIn);
            input.rewind();
            /* ******************************************************* */ 
 
            m_decryptCipher.doFinal(input, dataOut);
 
            return true; 
		}catch(Exception exc)
		{ 
			Logger.E(TAG, exc);