Unity3D -- MD5加密

查资料找到的一个unity的MD5加密写法,在这里写出来供大家参考。

using UnityEngine;
using System.Collections.Generic;
using System.Text;
using System;

public class Md5 : MonoBehaviour {
    public static string Md5Sum(string strToEncrypt)
    {
        byte[] bs = UTF8Encoding.UTF8.GetBytes (strToEncrypt);
        System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5CryptoServiceProvider.Create ();

        byte[] hashBytes = md5.ComputeHash (bs);

        string hashString = "";
        for (int i = 0; i < hashBytes.Length; i++) {
            hashString += System.Convert.ToString (hashBytes [i], 16).PadLeft (2, '0');
        }
        return hashString.PadLeft (32, '0');
    }
}

你可能感兴趣的:(Unity3D,unity3d,md5,加密)