c#中生成MD5

代码适用于在c#或unity中进行Md5生成

public string GetMD5(string secret, string ticket)
{
    string Add = secret + ticket;
    using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
    {
        byte[] inputBytes = Encoding.ASCII.GetBytes(Add);
        byte[] hashBytes = md5.ComputeHash(inputBytes);

        // Convert byte array to hexadecimal string
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < hashBytes.Length; i++)
        {
            sb.Append(hashBytes[i].ToString("x2"));
        }
        return sb.ToString();
    }
}

猜你喜欢

转载自blog.csdn.net/cherry_f_f/article/details/142979164