title: Need C# equivalent for the below SQL HashBytes function
body: <p>I have created hash value using below function in sql</p>
  
  <p>SQL query</p>
  
  <pre><code>Select hashbytes('MD5', PNumber+CONVERT(VARCHAR(50),cast(datestamp as  binary),1))   
  From dbo.Events
  </code></pre>
  
  <p>Now I need to get the equivalent C# function in order to get the hash value and pass it to a stored procedure.</p>
  
  <p>I am using below code to get the c# equivalent. But values are not matching</p>
  
  <p>C# Code</p>
  
  <pre><code>var strDate = policyEventFromQueue.DateStamp.ToString();
  var binaryvalue = Encoding.Unicode.GetBytes(strDate);
  var hashkey = GetMD5Hash(PNumber + binaryvalue);
  
  public static byte[] GetMD5Hash(string input)
  {
      System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
      byte[] bs = System.Text.Encoding.Unicode.GetBytes(input);
  
      bs = x.ComputeHash(bs);
      return bs;
  }
  </code></pre>
  
  <p>Here are test results:  </p>
  
  <p>From SQL Server:</p>
  
  <pre><code>PNumber ='4272535529'
  DateStamp ='2016-06-30 12:19:35.257961'
  
  HashValue : 0x104E09499B76CB59420AEEEDBBE187F8
  </code></pre>
  
  <p>In C# I am getting the value from DB Field value as below</p>
  
  <pre><code>[0]: 16
  [1]: 78
  [2]: 9
  [3]: 73
  [4]: 155
  [5]: 118
  [6]: 203
  [7]: 89
  [8]: 66
  [9]: 10
  [10]: 238
  [11]: 237
  [12]: 187
  [13]: 225
  [14]: 135
  [15]: 248
  </code></pre>
  
  <p>From C# GetMD5Hash Function i am getting value as below</p>
  
  <pre><code>[0]: 30
  [1]: 153
  [2]: 105
  [3]: 203
  [4]: 34
  [5]: 124
  [6]: 20
  [7]: 12
  [8]: 207
  [9]: 113
  [10]: 210
  [11]: 144
  [12]: 18
  [13]: 145
  [14]: 22
  [15]: 36
  </code></pre>
  
  <p>Any suggestion will be appreciated.</p>