- 本站大部分内容从网上收集,收集目的仅供研究、学习。涉及版权或不希望收录您的文章请您及时与我联系。
- 本站IM群,请自行选择。请各位朋友按照自己喜好加入。加入群后请及时发言,防止被清理。谢谢您的合作!!!
- QQ群:Y①WEB开发(ASP.NET)号码:7351660 QQ群:Y②WEB开发(ASP+.NET)号码:11864905
- QQ群:Y③WEB开发(DIV+CSS)号码:16610506 QQ群:Y④WEB开发(JS+AJAX)号码:16143998
- QQ群:Y⑤WEB开发(新手)号码:12777715 MSN群:yaosansi[at]126.com
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace MyHash
{
class md5
{
/// <summary>
/// 实现对一个文件md5的读取,path为文件路径
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public string md5_hash(string path)
{
try
{
FileStream get_file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
System.Security.Cryptography.MD5CryptoServiceProvider get_md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hash_byte = get_md5.ComputeHash(get_file);
string resule = System.BitConverter.ToString(hash_byte);
resule = resule.Replace("-", "");
return resule;
}
catch (Exception e)
{
return e.ToString();
}
System.Security.Cryptography.MD5CryptoServiceProvider get_md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] hash_byte = get_md5.ComputeHash(get_file);
string resule = System.BitConverter.ToString(hash_byte);
resule = resule.Replace("-", "");
return resule;
}
catch (Exception e)
{
return e.ToString();
}
}
}
}
===================================================
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Security.Cryptography;
public static void getFileMD5(string path)
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] md5byte = md5.ComputeHash(fs);
int i, j;
foreach (byte b in md5byte)
{
i = Convert.ToInt32(b);
j = i >> 4;
Console.Write(Convert.ToString(j, 16));
j = ((i << 4) & 0x00ff) >> 4;
Console.Write(Convert.ToString(j, 16));
}
Console.ReadLine();
}
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] md5byte = md5.ComputeHash(fs);
int i, j;
foreach (byte b in md5byte)
{
i = Convert.ToInt32(b);
j = i >> 4;
Console.Write(Convert.ToString(j, 16));
j = ((i << 4) & 0x00ff) >> 4;
Console.Write(Convert.ToString(j, 16));
}
Console.ReadLine();
}
订阅本站,阅读更多文章