Project/02 - Engine/LittleBigEngine/Utils/Hash.cs
/// <summary>
/// Create an md5 sum string of a string
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
Create an md5 sum string of a string
Create an md5 sum string of a string
static public string GetMd5Sum(string str)
        {
            Encoder enc = System.Text.Encoding.Unicode.GetEncoder();
            byte[] unicodeText = new byte[str.Length * 2];
            enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] result = md5.ComputeHash(unicodeText);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < result.Length; i++)
            {
                sb.Append(result[i].ToString("X2"));
            }
            return sb.ToString();
        }
static public string GetMd5Sum ( string str ) { Encoder enc = System . Text . Encoding . Unicode . GetEncoder ( ) ; byte [ ] unicodeText = new byte [ str . Length * 2 ] ; enc . GetBytes ( str . ToCharArray ( ) , 0 , str . Length , unicodeText , 0 , true ) ; MD5 md5 = new MD5CryptoServiceProvider ( ) ; byte [ ] result = md5 . ComputeHash ( unicodeText ) ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < result . Length ; i ++ ) { sb . Append ( result [ i ] . ToString ( " " ) ) ; } return sb . ToString ( ) ; }
Create an md5 sum string of a string
Create an md5 sum string of a string
// First we need to convert the string into bytes, which // means using a text encoder. // Create a buffer large enough to hold the string // Now that we have a byte array we can ask the CSP to hash it // Build the final string by converting each byte // into hex and appending it to a StringBuilder // And return it
None
str
string
None