title: Encrypt in python and decrypt in Java with AES-CFB
body: <p>I am aware of a question very similar to this (<a href="https://stackoverflow.com/questions/10440777/how-do-i-encrypt-in-python-and-decrypt-in-java">How do I encrypt in Python and decrypt in Java?</a>) but I have a different problem.</p>
  
  <p>My problem is, I am not able to decrypt in Java correctly. Despite using the correct key and IV, I still get garbage characters after decryption. I don't have any compile/run-time errors or exceptions in Java so I believe I am using the right parameters for decryption.</p>
  
  <p>Python Encryption Code - </p>
  
  <pre><code>from Crypto.Cipher import AES
  import base64
  key = '0123456789012345'
  iv = 'RandomInitVector'
  raw = 'samplePlainText'
  cipher = AES.new(key,AES.MODE_CFB,iv)
  encrypted = base64.b64encode(iv + cipher.encrypt(raw))
  </code></pre>
  
  <p>Java Decryption Code - </p>
  
  <pre><code>private static String KEY = "0123456789012345";
  public static String decrypt(String encrypted_encoded_string) throws NoSuchAlgorithmException, NoSuchPaddingException,
      InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
  
        String plain_text = "";
        try{
            byte[] encrypted_decoded_bytes = Base64.getDecoder().decode(encrypted_encoded_string);
            String encrypted_decoded_string = new String(encrypted_decoded_bytes);
            String iv_string = encrypted_decoded_string.substring(0,16); //IV is retrieved correctly.
  
            IvParameterSpec iv = new IvParameterSpec(iv_string.getBytes());
            SecretKeySpec skeySpec = new SecretKeySpec(KEY.getBytes("UTF-8"), "AES");
  
            Cipher cipher = Cipher.getInstance("AES/CFB/NoPadding");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
  
            plain_text = new String(cipher.doFinal(encrypted_decoded_bytes));//Returns garbage characters
            return plain_text;
  
        }  catch (Exception e) {
              System.err.println("Caught Exception: " + e.getMessage());
        }
  
        return plain_text;
   }
  </code></pre>
  
  <p>Is there anything obvious that I am missing?</p>