title: Truncating a byte array vs. substringing the Encoded string coming out of SHA-256
body: <p>I am not familiar with Hashing algorithms and the risks associated when using them and therefore have a question on the answer below that I received on a previous question . . .  </p>
  
  <blockquote>
    <p>Based on the comment that the hash value must, when encoded to ASCII, fit within 16 ASCI characters, the solution is first, to choose some cryptographic hash function (the SHA-2 family includes SHA-256, SHA-384, and SHA-512) 
    then, to truncate the output of the chosen hash function to 96 bits (12 bytes) - that is, keep the first 12 bytes of the hash function output and discard the remaining bytes 
    then, to base-64-encode the truncated output to 16 ASCII characters (128 bits) 
    yielding effectively a 96-bit-strong cryptographic hash. </p>
  </blockquote>
  
  <p>If I substring the base-64-encoded string to 16 characters is that fundamentally different then keeping the first 12 bytes of the hash function and then base-64-encoding them? If so, could someone please explain (provide example code) for truncating the byte array?</p>
  
  <p>I tested the substring of the full hash value against 36,000+ distinct values and had no collisions. The code below  is my current implementation.</p>
  
  <p>Thanks for any help (and clarity) you can provide.</p>
  
  <pre><code>public static byte[] CreateSha256Hash(string data)
  {
      byte[] dataToHash = (new UnicodeEncoding()).GetBytes(data);
      SHA256 shaM = new SHA256Managed();
      byte[] hashedData = shaM.ComputeHash(dataToHash);
  
      return hashedData;
  }
  
  public override void InputBuffer_ProcessInputRow(InputBufferBuffer Row)
  {
      byte[] hashedData = CreateSha256Hash(Row.HashString);
  
      string s = Convert.ToBase64String(hashedData, Base64FormattingOptions.None);
  
      Row.HashValue = s.Substring(0, 16);
  
  
  }
  </code></pre>
  
  <p>[Original post]
  (http://stackoverflow.com/questions/4340471/is-there-a-hash-algorithm-that-produces-a-hash-size-of-64-bits-in-c)</p>