MD5各种长度加密字符、验证MD5等操作辅助类 MD5Util
/// <summary>
/// 获得32位的MD5加密
/// </summary>
public static string GetMD5_32(string input)
/// <summary>
/// 获得16位的MD5加密
/// </summary>
public static string GetMD5_16(string input)
/// <summary>
/// 获得8位的MD5加密
/// </summary>
public static string GetMD5_8(string input)
/// <summary>
/// 获得4位的MD5加密
/// </summary>
public static string GetMD5_4(string input)
/// <summary>
/// 添加MD5的前缀,便于检查有无篡改
/// </summary>
public static string AddMD5Profix(string input)
/// <summary>
/// 移除MD5的前缀
/// </summary>
public static string RemoveMD5Profix(string input)
/// <summary>
/// 验证MD5前缀处理的字符串有无被篡改
/// </summary>
public static bool ValidateValue(string input)
#region MD5签名验证
/// <summary>
/// 对给定文件路径的文件加上标签
/// </summary>
/// <param name="path">要加密的文件的路径</param>
/// <returns>标签的值</returns>
public static bool AddMD5(string path)
/// <summary>
/// 对给定路径的文件进行验证,如果一致返回True,否则返回False
/// </summary>
/// <param name="path"></param>
/// <returns>是否加了标签或是否标签值与内容值一致</returns>
public static bool CheckMD5(string path)
、、、、、
//为文件增加MD5编码标签,然后验证是否被修改
string file = @"c:\test.xls";
bool flag2 = MD5Util.AddMD5(file);
Console.WriteLine(flag2);
//对给定路径的文件进行验证,如果一致返回True,否则返回False
bool flag3 = MD5Util.CheckMD5(file);
Console.WriteLine(flag3);