title: Why does my Base64 encoded hash only contain 28 characters?
body: <p>The <a href="https://stackoverflow.com/questions/20075378/why-does-my-base64-encoded-sha-1-hash-contain-56-chars">inverse question exists</a> with no answer and a comment that I don't understand.</p>
  
  <p>I am attempting to create a Base64 encoded <a href="https://msdn.microsoft.com/en-us/library/system.security.cryptography.hmacsha1(v=vs.110).aspx" rel="nofollow noreferrer">HMAC-SHA1</a> signature for a pseudo OAuth authentication header for an API. I found a support document (requires authenticated access) that takes you through the evolution of creating the signature. I'm able to create the same data up until the final step which is to Base64 encode the hash.</p>
  
  <p>The support document states that the HMAC-SHA1 signature is:</p>
  
  <pre><code>cb5acd2d3ef689a8fbec4d06c576371834689673
  </code></pre>
  
  <p>And I get:</p>
  
  <pre><code>CB5ACD2D3EF689A8FBEC4D06C576371834689673
  </code></pre>
  
  <p>The support document then states </p>
  
  <blockquote>
    <p>From the hex result string in step 3, encode the value using Base64</p>
  </blockquote>
  
  <p>and provides the following Base64 encoded result (58 characters):</p>
  
  <pre><code>Y2I1YWNkMmQzZWY2ODlhOGZiZWM0ZDA2YzU3NjM3MTgzNDY4OTY3Mw==
  </code></pre>
  
  <p>When I use <code>Convert.ToBase64String()</code> to convert my signature I get (28 characters):</p>
  
  <pre><code>y1rNLT72iaj77E0GxXY3GDRolnM=
  </code></pre>
  
  <p>I'm stumped, I don't know if the support document is incorrect or if I'm doing something wrong. The fact that I'm generating a string that is 28 characters and the example is 56 is too interesting to ignore.</p>
  
  <p>The comment in the <a href="https://stackoverflow.com/questions/20075378/why-does-my-base64-encoded-sha-1-hash-contain-56-chars">aforementioned semi-duplicate question</a> also stumps me. I don't see how the string "MDY" translates to any ascii or unicode digits that make sense to me - I don't understand how the comment author came to that conclusion.</p>
  
  <blockquote>
    <p>The hex value is being encoded as text ("062..." == 0x30, 0x36, 0x32,
    ...) rather than as the large number it represents.</p>
  </blockquote>