public byte[] encrypt(byte[] plainTextAsBytes,CharSequence password) throws KeyCrypterException {
  try {
    byte[] salt=new byte[SALT_LENGTH];
    secureRandom.nextBytes(salt);
    ParametersWithIV key=(ParametersWithIV)getAESPasswordKey(password,salt);
    BufferedBlockCipher cipher=new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
    cipher.init(true,key);
    byte[] encryptedBytes=new byte[cipher.getOutputSize(plainTextAsBytes.length)];
    final int processLength=cipher.processBytes(plainTextAsBytes,0,plainTextAsBytes.length,encryptedBytes,0);
    final int doFinalLength=cipher.doFinal(encryptedBytes,processLength);
    return concat(salt,Arrays.copyOf(encryptedBytes,processLength + doFinalLength));
  }
 catch (  Exception e) {
    throw new KeyCrypterException("Could not encrypt bytes '" + Utils.bytesToHexString(plainTextAsBytes) + "'",e);
  }
}

public byte [ ] encrypt ( byte [ ] plainTextAsBytes , CharSequence password ) throws KeyCrypterException { try { byte [ ] salt = new byte [ SALT_LENGTH ] ; secureRandom . nextBytes ( salt ) ; ParametersWithIV key = ( ParametersWithIV ) getAESPasswordKey ( password , salt ) ; BufferedBlockCipher cipher = new PaddedBufferedBlockCipher ( new CBCBlockCipher ( new AESFastEngine ( ) ) ) ; cipher . init ( true , key ) ; byte [ ] encryptedBytes = new byte [ cipher . getOutputSize ( plainTextAsBytes . length ) ] ; final int processLength = cipher . processBytes ( plainTextAsBytes , 0 , plainTextAsBytes . length , encryptedBytes , 0 ) ; final int doFinalLength = cipher . doFinal ( encryptedBytes , processLength ) ; return concat ( salt , Arrays . copyOf ( encryptedBytes , processLength + doFinalLength ) ) ; } catch ( Exception e ) { throw new KeyCrypterException ( "Could not encrypt bytes '" + Utils . bytesToHexString ( plainTextAsBytes ) + "'" , e ) ; } }
password based encryption using aes - cbc 256 bits .
