title: Java Base64 encoded string vs. .NET Base64 encoded string
body: <p><strong>Problem:</strong>  I have a .NET HTTP Handler taking an HTTP POST of XML which is originating, I believe, from a Java system.  One element contains a base64 string encoded document (current test file is a PDF).  When I take the original PDF and generate a base64 string from .NET, there are some discrepancies between that and the corresponding text in the supplied XML.</p>
  
  <p>There are a number of places where one of three things occurs:</p>
  
  <ol>
  <li>The XML file places a single space where .NET places a plus</li>
  <li><p>Similarly, the XML file has pair of consecutive spaces inserted vs. .NET's plusses</p>
  
  <p><code>PgplbmRv  YmoKNSAw</code>   vs.  <code>PgplbmRv++YmoKNSAw</code></p></li>
  <li><p>Sometimes the XML file has pair of consecutive spaces inserted vs. .NET's plusses <em>and</em> additional spaces are added nearby in the XML's version</p>
  
  <p><code>3kuPs  85QZWYaw  BsMNals</code>   vs.  <code>3kuPs  85QZWYaw++BsMNals</code></p></li>
  <li><p>Source XML will have four spaces (display below looks like 2 spaces) vs. .NET's has a pair of consecutive plusses </p>
  
  <p><code>vGDmKEJ    gnJeOK</code>  vs.  <code>vGDmKEJ++gnJeOK</code></p></li>
  </ol>
  
  <p>Also, there are no plusses in the source (Java created?) data.  </p>
  
  <p><strong>Questions:</strong>  Can someone help identify what would cause these discrepancies might be?  Most pressingly how I might address them as I can't see a reliable pattern against which to search and replace?</p>
  
  <p><strong>Edit:</strong>  When the POST arrives, it does do URL decoding before deserializing to an object.</p>
  
  <pre><code>public void ProcessRequest(HttpContext context)
  {
      try
      {
          StreamReader reader = new StreamReader(context.Request.InputStream);
          context.Response.ContentType = "text/plain";
          var decodedRequest = HttpUtility.UrlDecode(reader.ReadToEnd());
          ...
  </code></pre>