首先引用这个命名空间using System.Security.Cryptography;SHA1 sha = new SHA1CryptoServiceProvider();
//建立SHA1对象ASCIIEncoding enc = new ASCIIEncoding();
//将mystr转换成byte[]
byte[] dataToHash = enc.GetBytes(mystr);
byte[] dataHashed = SHA1.ComputeHash(dataToHash );
//Hash运算
string hash = BitConverter.ToString(dataHashed).Replace("-", "");
//将运算结果转换成string
return hash;