- 
      
 - 
        
Save jchandra74/f96bbf33cb1a68539626 to your computer and use it in GitHub Desktop.  
    SHA1 Hash for Unicode string
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | using System.Security.Cryptography; | |
| using System.Text; | |
| namespace Snippets | |
| { | |
| public static class SHA1Util | |
| { | |
| pubilc static string SHA1HashStringForUTF8String(string stringToBeHashed) | |
| { | |
| byte[] bytes = Encoding.UTF8.GetBytes(stringToBeHashed); | |
| var sha1 = SHA1.Create(); | |
| byte[] hashBytes = sha1.ComputeHash(bytes); | |
| return HexStringFromBytes(hashBytes); | |
| } | |
| public static string HexStringFromBytes(byte[] bytes) | |
| { | |
| var sb = new StringBuilder(); | |
| foreach (byte b in bytes) | |
| { | |
| var hex = b.ToString("x2"); | |
| sb.Append(hex); | |
| } | |
| return sb.ToString(); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Added a method to create SHA1 Hash from Unicode string. Needed a C# equivalent of SQL Server SHA1 hash on nvarchar field.