
使用:例如要保存用户密码,可以把加密后的密码存到数据库中,使用时,只需要将现有的与数据库的相比较就可以,无须解密。
MD5对文件的加密,思路也一样,using System.Security.Cryptography;
public static string FileMd5Value(string path)
{
try
{
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
MD5CryptoServiceProvider getMd5 = new MD5CryptoServiceProvider();
byte[] hash_byte = getMd5.ComputeHash(fs);//计算指定字节的希哈值
string result = BitConverter.ToString(hash_byte);
result = result.Replace("-", "");
return result;
}
catch (Exception)
{
return null;
}
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23109131/viewspace-631475/ ,如需转载,请注明出处,否则将追究法律责任。