Created
February 29, 2016 10:23
-
-
Save sunny352/7ffed837a994289c748c to your computer and use it in GitHub Desktop.
方便自己使用的MD5,可用在Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Security.Cryptography; | |
using System.Text; | |
public class HashTools | |
{ | |
public static byte[] GenMD5(byte[] source) | |
{ | |
MD5 md5 = new MD5CryptoServiceProvider(); | |
return md5.ComputeHash(source); | |
} | |
public static byte[] GenMD5(string source) | |
{ | |
MD5 md5 = new MD5CryptoServiceProvider(); | |
return md5.ComputeHash(Encoding.UTF8.GetBytes(source)); | |
} | |
public static string GenMD5String(byte[] source) | |
{ | |
return GenHEX(GenMD5(source)); | |
} | |
public static string GenMD5String(string source) | |
{ | |
return GenHEX(GenMD5(source)); | |
} | |
public static string GenHEX(byte[] source) | |
{ | |
return BitConverter.ToString(source).Replace("-", ""); | |
} | |
public static string GenHEX(byte[] source, bool replace) | |
{ | |
if (replace) | |
{ | |
return BitConverter.ToString(source).Replace("-", ""); | |
} | |
else | |
{ | |
return BitConverter.ToString(source); | |
} | |
} | |
public static string GenBase64(byte[] source) | |
{ | |
return Convert.ToBase64String(source); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment