Skip to content

Instantly share code, notes, and snippets.

@inogo
Created December 23, 2011 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save inogo/1514320 to your computer and use it in GitHub Desktop.
Save inogo/1514320 to your computer and use it in GitHub Desktop.
SHA1
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