using System.IO;
using System.Text;
namespace FileService
{
public static class ExtensionMethods
{
public static string MD5Code(this FileInfo fileInfo)
{
var data = fileInfo.BinaryData();
byte[] hash = new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(data);
var builder = new StringBuilder();
foreach (var b in hash)
{
builder.AppendFormat("{0:x2}", b);
}
return builder.ToString();
}
public static byte[] BinaryData(this FileInfo fileInfo)
{
return File.ReadAllBytes(fileInfo.FullName);
}
}
}
using System.Text;
namespace FileService
{
public static class ExtensionMethods
{
public static string MD5Code(this FileInfo fileInfo)
{
var data = fileInfo.BinaryData();
byte[] hash = new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(data);
var builder = new StringBuilder();
foreach (var b in hash)
{
builder.AppendFormat("{0:x2}", b);
}
return builder.ToString();
}
public static byte[] BinaryData(this FileInfo fileInfo)
{
return File.ReadAllBytes(fileInfo.FullName);
}
}
}
抓檔案的binary 及 MD5