第一篇随笔——NeverStopMamba

C#语言的MD5加密方法

/// <summary>
/// md5加密
/// </summary>
/// <param name="encypStr"></param>
/// <returns></returns>
private string GetMD5(string encypStr)
{
  string retStr;
  MD5CryptoServiceProvider m5 = new MD5CryptoServiceProvider();

  //创建md5对象
  byte[] inputBye;
  byte[] outputBye;

  //使用GB2312编码方式把字符串转化为字节数组.
  inputBye = Encoding.GetEncoding("GB2312").GetBytes(encypStr);

  outputBye = m5.ComputeHash(inputBye);

  retStr = System.BitConverter.ToString(outputBye);
  retStr = retStr.Replace("-", "").ToUpper();
  return retStr;
}

posted @ 2018-10-25 11:12  Manson叔叔  阅读(103)  评论(0)    收藏  举报