C# SHA1加密
SHA1加密
1.引用命名空间
using System.Security.Cryptography;
2.编码
/**
* SHA1加密
* @return SHA1加密结果
*/
public static string EncryptBySHA1(string cleartext)
{
using (HashAlgorithm hashAlgorithm = new SHA1CryptoServiceProvider())
{
byte[] utf8Bytes = Encoding.UTF8.GetBytes(cleartext);
byte[] hashBytes = hashAlgorithm.ComputeHash(utf8Bytes);
StringBuilder builder = new StringBuilder();
foreach (byte hashByte in hashBytes)
{
builder.AppendFormat("{0:x2}", hashByte);
}
return builder.ToString();
}
}

浙公网安备 33010602011771号