C# MD5加密
2021-02-16 17:17
阅读:813
标签:ide nbsp use utf8 def tostring return str 字符串
public static string MD5(string encypStr) { return MD5(encypStr, "utf-8"); } /** 获取大写的MD5签名结果 */ public static string MD5(string encypStr, string charset) { System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] bs = Encoding.GetEncoding(charset).GetBytes(encypStr); bs = md5.ComputeHash(bs); return BytesToHexString(bs); }
////// MD5 16位加密 /// /// /// public static string GetMd5Str(string ConvertString) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8); t2 = t2.Replace("-", ""); return t2; } /// /// MD5 32位加密 /// /// /// public static string UserMd5(string str) { string cl = str; string pwd = ""; System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();//实例化一个md5对像 // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl)); // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得 for (int i = 0; i ) { // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符 ,x则为小写 pwd = pwd + s[i].ToString("x"); } return pwd; }
C# MD5加密
标签:ide nbsp use utf8 def tostring return str 字符串
原文地址:https://www.cnblogs.com/Cein/p/8406414.html
上一篇:C#AES加密
下一篇:TensorFlow实现Softmax Regression识别手写数字中"TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主
评论
亲,登录后才可以留言!