标签:blog os 文件 for ar div log new
1、计算文本哈希值:
public static string jiami(string password) { byte[] buffer = System.Text.Encoding.UTF8.GetBytes(password); SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider(); byte[] hash = sha.ComputeHash(buffer); StringBuilder passwordbullder = new StringBuilder(32); foreach (byte hashByte in hash) { passwordbullder.Append(hashByte.ToString("x2")); } return passwordbullder.ToString(); }
2、计算文件的哈希值:
FileStream fs = new FileStream(this.fileFullName, FileMode.Open, FileAccess.Read); SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider(); Byte[] fileHashes_SHA1 = sha1.ComputeHash(fs); MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); Byte[] fileHashes_MD5 = md5.ComputeHash(fs); //this.fileSize = fs.Length; //this.sendSize = 0; fs.Close(); fs.Dispose();
标签:blog os 文件 for ar div log new
原文地址:http://www.cnblogs.com/shenchao/p/3922471.html