title: What's a C# equivalent of hexdigest in Python 3.2?
body: <p>I'm currently working on a project to convert a Python 3.2 program to C#.</p>
  
  <p>In the python program there's a line of code which returns a string object of double length, containing only hexadecimal digits.</p>
  
  <p>The bit of code in the Python program is:</p>
  
  <pre><code>if sha1.hexdigest().upper() == hash_string:
      #do whatever
  </code></pre>
  
  <p>I've been trying and failing to find an equivalent in C# of hexdigest from the hashlib in python.</p>
  
  <p>In C# I've already got the SHA1 hash in a byte array but all the methods I've tried to carry out an equivalent of hexdigest have failed to provide a match to the hash_string - which is what the hexdigest of sha1 <em>should</em> match.</p>
  
  <p>I'm not sure whether the problem is the method I'm using to emulate hexdigest or the method I use to generate the sha1 hash in the first place - so it'd be brilliant if anyone had a hexdigest method which they <em>know</em> works as that'd allow me to eliminate at least one possible cause of the problem.</p>
  
  <p>The method I'm using at the moment in place of hexdigest is:</p>
  
  <pre><code>string hexaHash = "";
  foreach (byte b in sha1result)
  {
      hexaHash += String.Format("{0:x2}", b);
  }
  string result = hexaHash;
  </code></pre>
  
  <p>EDIT: <em>facepalm</em> okay, I just worked out what my problem was. When generating the sha1 hash in the python it was doing it from a lower case hex string. In my C# it was an upper case hex string. So I'd guess that the hexdigest equivalent I'm using is fine as it is. Sorry for wasting people's time.</p>