您的问题似乎不完整,您是想询问关于C语言编程的某个具体问题吗?比如C语言的语法、编程技巧、项目开发等。请提供更具体的信息,这样我才能给出更准确的回答。
摘要:因工作需要对文件进行是否被修改判断,整理的一段生成文件MD5码的代码: 1: public class FileHelper 2: { 3:4:对文件流进行MD5加密 5:6: public static s.
因工作需要对文件进行是否被修改判断,整理的一段生成文件MD5码的代码:
1: public class FileHelper
2: {
3: /// <summary>
4: /// 对文件流进行MD5加密
5: /// </summary>
6: public static string MD5Stream(Stream stream)
7: {
8: MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
9: md5.ComputeHash(stream);
10: byte[] b = md5.Hash;
11: md5.Clear();
12: StringBuilder sb = new StringBuilder(32);
13: for (int i = 0; i < b.Length; i++)
14: {
15: sb.Append(b[i].ToString("X2"));
16: }
17: return sb.ToString();
18: }
19: /// <summary>
20: /// 对文件进行MD5加密
21: /// </summary>
22: public static string MD5Stream(string filePath)
23: {
24: using (FileStream stream = File.Open(filePath, FileMode.Open))
25: {
26: return MD5Stream(stream);
27: }
28: }
29: }
.csharpcode, .csharpcode pre { font-size: small; color: rgba(0, 0, 0, 1); font-family: consolas, "Courier New", courier, monospace; background-color: rgba(255, 255, 255, 1) }
.csharpcode pre { margin: 0 }
.csharpcode .rem { color: rgba(0, 128, 0, 1) }
.csharpcode .kwrd { color: rgba(0, 0, 255, 1) }
.csharpcode .str { color: rgba(0, 96, 128, 1) }
.csharpcode .op { color: rgba(0, 0, 192, 1) }
.csharpcode .preproc { color: rgba(204, 102, 51, 1) }
.csharpcode .asp { background-color: rgba(255, 255, 0, 1) }
.csharpcode .html { color: rgba(128, 0, 0, 1) }
.csharpcode .attr { color: rgba(255, 0, 0, 1) }
.csharpcode .alt { background-color: rgba(244, 244, 244, 1); width: 100%; margin: 0 }
.csharpcode .lnum { color: rgba(96, 96, 96, 1) }
