title: How to encrypt string in Java and decrypt in Python?
body: <p>I have encrypted a string in Java using AES, and decrypt in Python. But, after decrypting in Python there are random chars here, not the expected output.</p>
  
  <pre><code>import javax.crypto.Cipher;
  import javax.crypto.spec.IvParameterSpec;
  import javax.crypto.spec.SecretKeySpec;
  import android.util.Base64;
  
  public class AESCrypt{
  
  public static final byte[] encBytes(byte[] srcBytes, byte[] key,
          byte[] newIv) throws Exception {
      Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
      SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
      IvParameterSpec iv = new IvParameterSpec(newIv);
      cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
      byte[] encrypted = cipher.doFinal(srcBytes);
      return encrypted;
  }
  
  public static final String encText(String sSrc)
          throws Exception {
      byte[] key = 
      {'a','r','e','y','o','u','o','k','a','r','e','y','o','u','o','k'};
      byte[] ivk = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
      byte[] srcBytes = sSrc.getBytes("utf-8");
      byte[] encrypted = encBytes(srcBytes, key, ivk);
      return Base64.encodeToString(encrypted,Base64.DEFAULT);
  }
  
  }
  </code></pre>
  
  <p>and python code is :</p>
  
  <pre><code>#!/usr/bin/env python
  
  from Crypto.Cipher import AES
  import base64
  
  key = 'areyouokareyouok'
  iv = '0000000000000000'
  
  BS = 16
  pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) 
  unpad = lambda s : s[0:-ord(s[-1])]
  
  def decrypt_aes(cryptedStr):
      generator = AES.new(key, AES.MODE_CBC, iv)
      cryptedStr = base64.b64decode(cryptedStr)
      recovery = generator.decrypt(cryptedStr)
      return unpad(recovery)
  
  sourceStr = 'Dur/0RHadPwToNWczq8xk3mBdjybyw/yaMgas1F+WLg='
  
  print decrypt_aes(sourceStr)
  </code></pre>
  
  <p>I can not understand why? Padding? </p>