...

[C#] SHA1校验函数用法

首先引用这个命名空间
using System.Security.Cryptography;


//建立SHA1对象
SHA1 sha = new SHA1CryptoServiceProvider();
 

//将mystr转换成byte[]
ASCIIEncoding enc = new ASCIIEncoding();
byte[] dataToHash = enc.GetBytes(mystr);

//Hash运算
byte[] dataHashed = SHA1.ComputeHash(dataToHash );

//将运算结果转换成string
string hash = BitConverter.ToString(dataHashed).Replace("-", "");

return hash;
posted @ 2017-04-11 20:03  回声小站  阅读(701)  评论(0编辑  收藏  举报