Skip to content

Instantly share code, notes, and snippets.

@jeffgca
Created April 12, 2011 17:23
Show Gist options
  • Select an option

  • Save jeffgca/915968 to your computer and use it in GitHub Desktop.

Select an option

Save jeffgca/915968 to your computer and use it in GitHub Desktop.
static method that behaves just like PHP, etc.
/// <summary>
/// plain string -> sha1 string implementation, behaves identically to php's sha1() function.
/// </summary>
/// <param name="input">
/// A <see cref="System.String"/>
/// </param>
/// <returns>
/// A <see cref="System.String"/>
/// </returns>
public static string sha1(string input) {
byte[] bytes = Encoding.ASCII.GetBytes(input);
var hashData = new SHA1Managed().ComputeHash(bytes);
string hash = String.Empty;
foreach ( byte b in hashData) {
hash += String.Format("{0:x2}", b);
}
return hash;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment