title: Coverting java code to php with AES and Cipher
body: <p>I am finding it difficult to convert a piece of code to php from java.
  I searched on the internet about the meaning of each line of code written in my java code example but I didn't find any.
  I want to understand what each line does in this particular example.</p>
  
  <p>This is what I tried.</p>
  
  <pre><code>function my_aes_encrypt($key, $data) {
   if(16 !== strlen($key)) $key = hash('MD5', $key, true);
   $padding = 16 - (strlen($data) % 16);
       $data .= str_repeat(chr($padding), $padding);
       return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_ECB, str_repeat("\0", 16)));
   }
  function my_aes_decrypt($str, $key){ 
       $str = base64_decode($str);
       $str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $str, MCRYPT_MODE_ECB);
       $block = mcrypt_get_block_size('rijndael_128', 'ecb');
       $pad = ord($str[($len = strlen($str)) - 1]);
       $len = strlen($str);
       $pad = ord($str[$len-1]);
       return substr($str, 0, strlen($str) - $pad);
  }
  </code></pre>
  
  <p>Convert from Java to PHP</p>
  
  <pre><code>//provided key 
  byte[] keyBinary = DatatypeConverter.parseBase64Binary("r/RloSflFkLj3Pq2gFmdBQ==");  
  SecretKey secret = new SecretKeySpec(keyBinary, "AES");    
  
  // encrypted string   
  byte[] bytes = DatatypeConverter.parseBase64Binary("IKWpOq9rhTAz/K1ZR0znPA=="); 
  
  // iv 
  byte[] iv = DatatypeConverter.parseBase64Binary("yzXzUhr3OAt1A47g7zmYxw==");       
  Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); 
  cipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(iv)); 
  String msisdn = new String(cipher.doFinal(bytes), "UTF-8"); 
  </code></pre>
  
  <p>It would be great if you guys let me know the details of each line written in Java.</p>