title: Php Decrypt a String from C# .NET RIJNDAEL 256
body: <p>Fixed it.</p>
  
  <pre><code>$data = base64_decode(str_replace(' ', '+', $_GET['data']));
  </code></pre>
  
  <p>for whatever reason, Php was converting the +'s from the GET variablesinto spaces</p>
  
  <p>--</p>
  
  <p>I am trying to decrypt a string that is being decrypted in C#.NET.</p>
  
  <p>The results of the code vary, There were several occasions where the final string had some parts decrypted, and the rest of it was random characters.</p>
  
  <p>Most of the time the "decrypted" string is just all random characters, I also tried some Php functions to remove PKCS7 padding but none of them fixed the problem.</p>
  
  <p>I've looked at several similar questions on the site but none of them were of help.</p>
  
  <p><strong>C#</strong></p>
  
  <pre><code>// called as Response.Redirect(url + encryptParams(param));
  
  private string encryptData(string data)
  {
      Rijndael aes = Rijndael.Create();
      aes.KeySize = 256;
      aes.BlockSize = 256;
      aes.Mode = CipherMode.CBC;
      aes.Padding = PaddingMode.PKCS7;
      aes.Key = Convert.FromBase64String("b0dJN2c6cklVUX1qUGlFfGMweXRKbH5fSEMuXjAgfQo=");
  
      ICryptoTransform crypto = aes.CreateEncryptor(aes.Key, aes.IV);
      byte[] txt = ASCIIEncoding.UTF8.GetBytes(data);          
      byte[] cipherText = crypto.TransformFinalBlock(txt, 0, txt.Length);
  
      return "&amp;data=" + Convert.ToBase64String(cipherText) + "&amp;iv=" + Convert.ToBase64String(aes.IV);
  }
  </code></pre>
  
  <p><strong>Php:</strong></p>
  
  <pre><code>   $data = base64_decode($_GET['data']);
     $iv = base64_decode($_GET['iv']);
  
     echo "&lt;br /&gt;&lt;b&gt;IV&lt;/b&gt;: " . $_GET['iv'] .
         "&lt;br /&gt;&lt;b&gt;Encrypted String&lt;/b&gt;: &lt;br /&gt;&lt;textarea&gt;".$_GET['data']."&lt;/textarea&gt;" .
         "&lt;br /&gt;&lt;b&gt;key size:&lt;/b&gt; " . mcrypt_get_key_size ( MCRYPT_RIJNDAEL_256,  MCRYPT_MODE_CBC) .
         "&lt;br /&gt;&lt;b&gt;block size:&lt;/b&gt; " . mcrypt_get_block_size ( MCRYPT_RIJNDAEL_256,  MCRYPT_MODE_CBC) .
         "&lt;br /&gt;&lt;b&gt;cipher:&lt;/b&gt; " . mcrypt_get_cipher_name ( MCRYPT_RIJNDAEL_256 ) .
         "&lt;br /&gt;&lt;b&gt;iv size:&lt;/b&gt; " .  mcrypt_get_iv_size  ( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC) . "&lt;br /&gt;"; 
  
     echo "Result: " . 
        mcrypt_decrypt
        (
            MCRYPT_RIJNDAEL_256,
            base64_decode("b0dJN2c6cklVUX1qUGlFfGMweXRKbH5fSEMuXjAgfQo="),
            $data,
            MCRYPT_MODE_CBC,
            $iv
         );
  </code></pre>
  
  <p><strong>Php output:</strong></p>
  
  <p><strong>IV:</strong> WzsMlG39tfCGuX2EQM3vq8CoqGA xC0nW jICls8Cno=<br>
  <strong>key</strong>: b0dJN2c6cklVUX1qUGlFfGMweXRKbH5fSEMuXjAgfQo=  </p>
  
  <p><strong>Encrypted String:</strong>  oLxa21fxfQGg0EJ5rwMjEzMblvcaTq0AInDAsD88wAkNeLqOdon0ukLjz49Hpp36KPTKcTGkj1f7EPYPAAbuADnr3Ff0zpptZkx2d22VRbHrMgj QLF9vDxQRT3er3UAXsAfKKTyW8qeSIgrzACFLX3yoro/bzWic rt7ED7y0jZ7a1Hci3GMz/4KhwaftarbV QQWStJlSOqdxAdmtRRe84Vi3085S6um51bNrh5QzGRH PcpucfqaTb3junfO9g67j2JUQaM/Tj1EGnv6oX3wATR/LuWyhnhrCH86u10I=</p>
  
  <p><strong>key size:</strong> 32<br>
  <strong>block size:</strong> 32<br>
  <strong>cipher:</strong> Rijndael-256<br>
  <strong>iv size:</strong> 32<br>
  <strong>Result:</strong>
  /ci�����^/�c�g�������s��c�(��</p>
  
  <p><strong>Original String (JSON):</strong>
  {"user":"jsmith","firstName":"John","lastName":"Smith","phone":"12223334444.5555","email":"john.smith@domain.com","address":"123 Some Street","address2":"apt 456","city":"Some City","state":"LA","zip":"55555"}</p>