using UnityEngine; using System.Collections; using System.Security.Cryptography; public class GetMD5 : MonoBehaviour { public string GetMD5Str(string str) { MD5 md5 = new MD5CryptoServiceProvider(); //将字符串转换为字节数组 byte[] fromData = System.Text.Encoding.Unicode.GetBytes(str); //计算字节数组的哈希值 byte[] toData = md5.ComputeHash(fromData); string byteStr = ""; for (int i = 0; i < toData.Length; i++) { byteStr += toData[i].ToString("x"); } return byteStr.Substring(0, 8); } }