title: C#: Base64 encoding
body: <p>Can anyone please let me know where I made a mistake in this code? This code is written in C#.NET. I need to write an algorithm for encoding a string using base64 format using C#.NET, and then decoded with base64_decode() using PHP. Please see the snippit below:</p>
  
  <pre><code>System.Security.Cryptography.RijndaelManaged rijndaelCipher = new System.Security.Cryptography.RijndaelManaged();
  rijndaelCipher.Mode = System.Security.Cryptography.CipherMode.CBC;
  rijndaelCipher.Padding = System.Security.Cryptography.PaddingMode.Zeros;
  rijndaelCipher.KeySize = 256;
  rijndaelCipher.BlockSize = 128;
  
  byte[] pwdBytes = System.Text.Encoding.UTF8.GetBytes(_key);
  byte[] keyBytes = new byte[16];
  
  int len = pwdBytes.Length;
  if (len &gt; keyBytes.Length) len = keyBytes.Length;
  
  System.Array.Copy(pwdBytes, keyBytes, len);
  
  rijndaelCipher.Key = keyBytes;
  rijndaelCipher.IV = keyBytes;
  
  System.Security.Cryptography.ICryptoTransform transform = rijndaelCipher.CreateEncryptor();
  
  byte[] plainText = Encoding.UTF8.GetBytes(unencryptedString);
  byte[] cipherBytes = transform.TransformFinalBlock(plainText, 0, plainText.Length);
  
  return Convert.ToBase64String(cipherBytes);
  </code></pre>