码迷,mamicode.com
首页 > 编程语言 > 详细

unity3d中求字符串md5

时间:2016-10-10 13:56:57      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

  • 方法一:此方法可在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

标签:

原文地址:http://www.cnblogs.com/Yellow0-0River/p/5945317.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!