title: Invalid length for a Base-64 char array during decoding/decryption
body: <p>Q: I face the following big problem :</p>
  
  <p>from time to another i find the following exception:</p>
  
  <p><strong>Invalid length for a Base-64 char array</strong></p>
  
  <p><em>I use encryption and decryption:</em></p>
  
  <pre><code>public static string Encrypt(string text)
          {
  
              try
              {
                  key = Encoding.UTF8.GetBytes(stringKey.Substring(0, 8));
                  DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                  Byte[] byteArray = Encoding.UTF8.GetBytes(text);
                  MemoryStream memoryStream = new MemoryStream();
                  CryptoStream cryptoStream = new CryptoStream(memoryStream,des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
                  cryptoStream.Write(byteArray, 0, byteArray.Length);
                  cryptoStream.FlushFinalBlock();
                  return Convert.ToBase64String(memoryStream.ToArray());
              }
  
              catch (Exception ex)
              {
                string message =  ex.Message;
              }
  
              return string.Empty;
          }
  
  
  
          public static string Decrypt(string text)
          {
              try
              {
                  key = Encoding.UTF8.GetBytes(stringKey.Substring(0, 8));
                  DESCryptoServiceProvider des = new DESCryptoServiceProvider();
                  text = text.Replace(" ", "+")
                  Byte[] byteArray = Convert.FromBase64String(text);
                  MemoryStream memoryStream = new MemoryStream();
                  CryptoStream cryptoStream = new CryptoStream(memoryStream,
                  des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
                  cryptoStream.Write(byteArray, 0, byteArray.Length);
                  cryptoStream.FlushFinalBlock();
                  return Encoding.UTF8.GetString(memoryStream.ToArray());
              }
  
              catch (Exception ex)
              {
                  string message = ex.Message;
  
              } 
  </code></pre>
  
  <p>i read many articles about the problem 
  some posts talking about the solution is:</p>
  
  <p><code>text = text.Replace(" ", "+")</code>
  and this not fixes my problem at all</p>
  
  <p>my string is :<code>3DZF/NZpp0yuQ=3D</code>
  please i need help to fix this problem.</p>
  
  <p><strong>EDIT</strong></p>
  
  <ul>
  <li><strong>If there are any modifications or
  enhancements to this class to make it
  work better or more secure or avoid
  any possible problems like this , i
  will be grateful.</strong></li>
  <li><strong>If there are alternating classes instead of this,more
  secure and doesn't make these
  problems , I will be  grateful.</strong></li>
  <li><strong>I use this class in a small
  application used to verifying mails.</strong></li>
  </ul>
  
  <hr>
  
  <p>EDIT:</p>
  
  <pre><code>Decoding the querystring values is done already when it's parsed into the Request.
  </code></pre>
  
  <p><a href="https://stackoverflow.com/a/10879400/418343">https://stackoverflow.com/a/10879400/418343</a></p>