title: How do I handle improper length Base64 strings with c#
body: <p>I know that a Base64 encoded file needs to have a length that is a multiple of 4. And to correct for that I can use the code below.</p>
  
  <pre><code>        int mod4 = s.Length % 4;
          if (mod4 &gt; 0)
          {
              s += new string('=', 4 - mod4);
          }
  </code></pre>
  
  <p>This will add as many "=" as it takes to make it a length that is a multiple of 4. But I'm stuck with a situation where "=" signs may be present when they shouldn't be. I suppose I could remove any padding "=" 's and then add them back in if needed, but that seems silly. Is there a better way to handle Base64 Encoding that are messed up?</p>