title: Log file, “Padding is invalid and cannot be removed”
body: <p>I found this on the error log file, but the website still working fine. I unable to reproduce the issue, I still worry about it because I saw this happens quite frequent on the error log.</p>
  
  <p>Anyone have what caused the error?</p>
  
  <pre><code>public static string Decrypt(string inputText)
  {
      if (String.IsNullOrEmpty(inputText))
          return string.Empty;
      RijndaelManaged rijndaelCipher = new RijndaelManaged();
      byte[] encryptedData = Convert.FromBase64String(inputText);
      PasswordDeriveBytes secretKey = new PasswordDeriveBytes(ENCRYPTION_KEY, SALT);
  
      using (ICryptoTransform decryptor = rijndaelCipher.CreateDecryptor(secretKey.GetBytes(32), secretKey.GetBytes(16)))
      {
          using (MemoryStream memoryStream = new MemoryStream(encryptedData))
          {
              using (CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
              {
                  byte[] plainText = new byte[encryptedData.Length];
                  int decryptedCount = cryptoStream.Read(plainText, 0, plainText.Length);
                  return Encoding.Unicode.GetString(plainText, 0, decryptedCount);
              }
          }
      }
  }
  </code></pre>
  
  <p>The error throws at the line below</p>
  
  <pre><code>return Encoding.Unicode.GetString(plainText, 0, decryptedCount);
  </code></pre>
  
  <p>And this is what saw on the error logs</p>
  
  <blockquote>
    <p></p>
  </blockquote>
  
  <pre><code>System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed.
     at System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]&amp; outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast)
     at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
     at System.Security.Cryptography.CryptoStream.FlushFinalBlock()
     at System.Security.Cryptography.CryptoStream.Dispose(Boolean disposing)
     at System.IO.Stream.Close()
     at QueryStringModule.Decrypt(String inputText) in line 135
     at QueryStringModule.context_BeginRequest(Object sender, EventArgs e) in E:\SSv45\Pages\QueryStringModule.cs:line 46
     at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
     at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously)
  </code></pre>
  
  <p>Thanks
  Ming-fei</p>