首页 > 代码库 > unity3d中求字符串md5

unity3d中求字符串md5

  • 方法一:此方法可在Android正常生成md5
    public string GetMD5(string msg)    {          MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();          byte[] data =http://www.mamicode.com/ System.Text.Encoding.UTF8.GetBytes(msg);          byte[] md5Data = http://www.mamicode.com/md5.ComputeHash(data, 0, data.Length);          md5.Clear();          string destString = "";          for (int i = 0; i < md5Data.Length; i++) {              destString += System.Convert.ToString(md5Data[i], 16).PadLeft(2, 0);          }          destString = destString.PadLeft(32, 0);          return destString;    }
  • 方法二:此方法在Android中md5对象为null,不能正常生成md5值
    public string GetMD5(string msg)    {          System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();         byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(msg);         byte[] hash = md5.ComputeHash(inputBytes);         StringBuilder sb = new StringBuilder();         for (int i = 0; i < hash.Length; i++)         {             sb.Append(hash[i].ToString("X2"));         }         return sb.ToString();     }

 

unity3d中求字符串md5