Created
December 9, 2010 08:01
-
-
Save erikzaadi/734467 to your computer and use it in GitHub Desktop.
A one liner method for MD5 Hashing / performance / verbose approach?
This file contains 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
public static string ToMD5(this string input) | |
{ | |
//comment about this | |
var sb = new System.Text.StringBuilder(); | |
//comment about that | |
var md5 = System.Security.Cryptography.MD5.Create(); | |
var bytesFromInput = System.Text.Encoding.Unicode.GetBytes(input); | |
var hashedBytes = md5.ComputeHash(bytesFromInput); | |
foreach (var byt in hashedBytes) | |
{ | |
//To Hexa comment blah | |
sb.Append(byt.ToString("X2")); | |
} | |
return sb.ToString(); | |
} |
This file contains 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
public static string CalculateMd5Hash(string input) | |
{ | |
return string.Join("", | |
System.Security.Cryptography.MD5.Create() | |
.ComputeHash(System.Text.Encoding.Unicode.GetBytes(input)) | |
.Select(byt => byt.ToString("X2"))); | |
} |
This file contains 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
public static string CalculateMd5HashBetterPerhaps(string input) | |
{ | |
var sb = new System.Text.StringBuilder(); | |
foreach (var byt in System.Security.Cryptography.MD5.Create() | |
.ComputeHash(System.Text.Encoding.Unicode.GetBytes(input))) | |
{ | |
sb.Append(byt.ToString("X2")); | |
} | |
return sb.ToString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wow) thats so cool!