title: Grails Base64 decoding of Authorization header malformed on decode
body: <p>I have a grails controller that base64 decodes the authorization header. I sent this from a PHP script using CURL.</p>
  
  <pre><code>curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, "testindia01@test.com:india123");
  </code></pre>
  
  <p>My grails console logging shows:</p>
  
  <pre><code>Authorization raw: Basic dGVzdGluZGlhMDFAdGVzdC5jb206aW5kaWExMjM=, isBase64: true
  Authorization decoded: ´"q—ïÕ—•πë•Ñ¿≈—ïÕ–πçΩ¥È•πë•Ñƒ»Ã
  </code></pre>
  
  <p>In the above case I am using the Commons Base64 class, but using the Groovy built-in decodeBase64 yields the same result.</p>
  
  <p>The Authorization raw coming in is correct. If I copy this and push it through PHP's ecode then it decodes properly.</p>
  
  <pre><code>echo base64_decode('dGVzdGluZGlhMDFAdGVzdC5jb206aW5kaWExMjM=');
  </code></pre>
  
  <p>If I copy the string directly into the controller, e.g.</p>
  
  <pre><code>def decode = new String(Base64.encodeBase64("dGVzdGluZGlhMDFAdGVzdC5jb206aW5kaWExMjM="))
  </code></pre>
  
  <p>Then this also correctly decodes.</p>
  
  <p>I acquire the header via the request</p>
  
  <pre><code>def auth = request.getHeader("Authorization")
  </code></pre>
  
  <p>I test it is a valid base64 string with</p>
  
  <pre><code>Base64.isBase64(auth)
  </code></pre>
  
  <p>It's just the decode that fails. I have tried changing encodings on the decode.</p>
  
  <p>def decoded = new String(auth.decodeBase64(), "UTF-8")</p>
  
  <p>As well as other encodings like ISO-8859-1 and Windows-1252 but each time a different malformed string is returned.</p>
  
  <p>I have also tried setting manually Accept-Encoding on the CURL request.</p>
  
  <p>I am out of ideas :(</p>