-
-
Save jchandra74/f96bbf33cb1a68539626 to your computer and use it in GitHub Desktop.
Revisions
-
jchandra74 revised this gist
Jun 2, 2015 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,21 @@ namespace Snippets { public static class SHA1Util { /// <summary> /// Compute hash for string encoded as UTF8 /// </summary> /// <param name="s">String to be hashed</param> /// <returns>40-character hex string</returns> public static string SHA1HashStringForUTF8String(string s) { byte[] bytes = Encoding.UTF8.GetBytes(s); var sha1 = SHA1.Create(); byte[] hashBytes = sha1.ComputeHash(bytes); return HexStringFromBytes(hashBytes); } /// <summary> /// Compute hash for Unicode encoded string. /// This is the exact same Hash that the following SQL Server SHA1 Hash will produce... -
jchandra74 revised this gist
Jun 2, 2015 . 1 changed file with 11 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ //Forked from kristopherjohnson/SHA1Util.cs gist using System.Security.Cryptography; using System.Text; @@ -6,18 +7,22 @@ namespace Snippets public static class SHA1Util { /// <summary> /// Compute hash for Unicode encoded string. /// This is the exact same Hash that the following SQL Server SHA1 Hash will produce... /// SET @hash = HASHBYTES('SHA1', @dataJson); /// SET @hash64str = cast('' as xml).value('xs:hexBinary(sql:variable("@hash"))', 'varchar(max)'); /// just in case you need to recreate the hash in C# /// </summary> /// <param name="s">String to be hashed</param> /// <returns>40-character hex string</returns> public static string SHA1HashStringForUnicodeString(string s) { byte[] bytes = Encoding.Unicode.GetBytes(s); var sha1 = SHA1.Create(); byte[] hashBytes = sha1.ComputeHash(bytes); return HexStringFromBytes(hashBytes).ToUpperInvariant(); } /// <summary> @@ -33,7 +38,7 @@ public static string HexStringFromBytes(byte[] bytes) var hex = b.ToString("x2"); sb.Append(hex); } return sb.ToString(); } } } -
kristopherjohnson revised this gist
Jun 29, 2012 . 1 changed file with 12 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,16 +5,26 @@ namespace Snippets { public static class SHA1Util { /// <summary> /// Compute hash for string encoded as UTF8 /// </summary> /// <param name="s">String to be hashed</param> /// <returns>40-character hex string</returns> pubilc static string SHA1HashStringForUTF8String(string s) { byte[] bytes = Encoding.UTF8.GetBytes(s); var sha1 = SHA1.Create(); byte[] hashBytes = sha1.ComputeHash(bytes); return HexStringFromBytes(hashBytes); } /// <summary> /// Convert an array of bytes to a string of hex digits /// </summary> /// <param name="bytes">array of bytes</param> /// <returns>String of hex digits</returns> public static string HexStringFromBytes(byte[] bytes) { var sb = new StringBuilder(); -
kristopherjohnson renamed this gist
Jun 29, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
kristopherjohnson revised this gist
Jun 29, 2012 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,10 @@ 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); @@ -18,3 +25,5 @@ public static string HexStringFromBytes(byte[] bytes) } return sb.ToString(); } } } -
kristopherjohnson created this gist
Jun 29, 2012 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ 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(); }