title: Determine the length of a base64url encoded string
body: <p>I am attempting to write a unit test to check that I'm hashing and encoding a string (actually, PEM certificate) correctly.</p>
  
  <p>What I'm doing is:</p>
  
  <ol>
  <li>Taking a certificate (in PEM format)</li>
  <li>Convert it to DER</li>
  <li>Run a hashing function on it to get a hashed value (SHA-1 / SHA-256)</li>
  <li>Base64Url encoding the hash</li>
  </ol>
  
  <p>The value of a SHA-256 hash has a constant length (256 bits).  This can be represented differently (hex / binary, etc) but it's the same underneath.  I'm storing the value in a Java byte array.</p>
  
  <p>My question is this: if I attempt to base64url encode this hashed byte array value, is the length of the resulting encoded string always the same?  Or will it vary depending on values present in the underlying hash?</p>
  
  <p>What I'm not clear on is the "url" part of the "base64url" encoding: because it makes the string safe for urls, does it do any sort of character expansion (for example, urlencoding replaces a single space character with %20 which is three characters).</p>