unity3d中求字符串md5
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了unity3d中求字符串md5相关的知识,希望对你有一定的参考价值。
- 方法一:此方法可在android正常生成md5
public string GetMD5(string msg) { MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] data = System.Text.Encoding.UTF8.GetBytes(msg); byte[] md5Data = 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的主要内容,如果未能解决你的问题,请参考以下文章
Java中求字符串String和数组Array的长度(length)