Created
December 23, 2011 14:15
-
-
Save inogo/1514320 to your computer and use it in GitHub Desktop.
SHA1
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; | |
using System.Text; | |
using System.Security.Cryptography; | |
static class Hashes | |
{ | |
public static string SHA1(string text) | |
{ | |
byte[] buffer = Encoding.UTF8.GetBytes(text); | |
var sha1 = new SHA1CryptoServiceProvider(); | |
return BitConverter.ToString(sha1.ComputeHash(buffer)).Replace("-", ""); | |
} | |
private static string MD5(string text) | |
{ | |
byte[] data = _hasher.ComputeHash(Encoding.Default.GetBytes(text)); | |
var sb = new StringBuilder(32); | |
for (int i = 0; i < data.Length; i++) | |
sb.Append(data[i].ToString("x2")); | |
return sb.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment