I have been trying to do some encryption-decryption using bouncy castle and with the available docs and samples on the internet I have managed to prepare the below. Though this works without throwing any exception, i feel something fishy. Can somebody tell me if i have done it right or is there any thing that i should do :) private static void Test()  {  try  {      String keyString = Olmy9iqs1LwWblwe;       String input = teststring;    byte[] inputBytes = input.getBytes();    String xiv = 1234567891234567;    byte[] iv = xiv.getBytes(UTF-8);    int length;    //Set up    AESEngine engine = new AESEngine();    CBCBlockCipher blockCipher = new CBCBlockCipher(engine);     PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(blockCipher);     KeyParameter keyParam = new KeyParameter(keyString.getBytes());    ParametersWithIV keyParamWithIV = new ParametersWithIV(keyParam, iv, 0, 16);    // Encrypt    cipher.init(true, keyParamWithIV);    byte[] outputBytes = new byte[cipher.getOutputSize(inputBytes.length)];     length = cipher.processBytes(inputBytes,0,inputBytes.length, outputBytes, 0);    cipher.doFinal(outputBytes, length);     String encryptedInput = new String(Base64.encode(outputBytes));    System.out.println(Encrypted String: +encryptedInput);    //Decrypt                cipher.init(false, keyParamWithIV);    byte[] out2 = Base64.decode(encryptedInput);    byte[] comparisonBytes = new byte[cipher.getOutputSize(out2.length)];    length = cipher.processBytes(out2, 0, out2.length, comparisonBytes, 0);    cipher.doFinal(comparisonBytes, length); //Do the final block    String s2 = new String(comparisonBytes);    System.out.println(Decrypted String:+s2);}  catch (Exception e)   {    e.printStackTrace();  }}
Bouncy castle 128bit AES/CBC/PKCS7 in java
java;aes
Some observations:It is best to always specify the encoding when converting from a string to a byte array:input.getBytes()     -> input.getBytes(UTF-8)keyString.getBytes() -> keyString.getBytes(UTF-8)The IV should be an array of random bytes unique for each encryption, usually created from a CSPRNG. Then prefix the encrypted data with the IV for use during decryption, the IV does not need to be secret.When using a password it is necessary to derive the key from it with a function such as PBKDF2.