title: Decrypt text created with Rijndael method in powershell from a php script
body: <p>Can someone please help me with a php script to decrypt a value in php that is being created in powershell using the Rijndael key.</p>
  
  <p>The powershell script I've used to create it is below</p>
  
  <pre><code>[Reflection.Assembly]::LoadFile('C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.dll') | out-null 
  $XCADMPass = "CloudyTest"
  $r = new-Object System.Security.Cryptography.RijndaelManaged  # use Rijndael  symmetric key encryption
  $c = $r.CreateEncryptor((1..16), (1..16))    # Set the key and initialisation vector to 128-bytes each of (1..16)
  $ms = new-Object IO.MemoryStream
  $cs = new-Object Security.Cryptography.CryptoStream $ms,$c,"Write" # Target data stream, transformation, and mode
  $sw = new-Object IO.StreamWriter $cs
  $sw.Write($XCADMPass)       # Write the string through the crypto stream into the memory stream
  $sw.Close()
  $cs.Close()
  $ms.Close()
  $r.Clear()
  [byte[]]$result = $ms.ToArray()      # Byte array from the encrypted memory stream
  $encPass = [Convert]::ToBase64String($result)
  </code></pre>
  
  <p>The encrypted value is   <code>yD3/YeGk64JJ2LUI20mo8Q==</code> </p>
  
  <p>I've tried using mcrypt_decrypt but can't figure out the correct way to get my original text.</p>
  
  <p>This is what i've tried</p>
  
  <pre><code>$input = "yD3/YeGk64JJ2LUI20mo8Q==";
  $key = "12345678910111213141516";
  $data = base64_decode($input);
  $iv = substr($data, 0, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
  
  $decrypted = rtrim(
  mcrypt_decrypt(
      MCRYPT_RIJNDAEL_128,
      $key,
      substr($data, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)),
      MCRYPT_MODE_CBC,
      $iv
  ),
  "\0"
  );
  </code></pre>
  
  <p>I'm clearly going wrong somewhere so any help would be much appreciated.</p>