facebook twitter hatena line email

Unity/Csharp/md5

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

サンプルコード

// KeyUtility.md5("hoge");
public class KeyUtility {
	public static string md5( string srcStr ) {
		System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
		byte[] srcBytes = System.Text.Encoding.UTF8.GetBytes(srcStr);
		byte[] destBytes = md5.ComputeHash(srcBytes);
		System.Text.StringBuilder destStrBuilder;
		destStrBuilder = new System.Text.StringBuilder();
		foreach (byte curByte in destBytes) {
			destStrBuilder.Append(curByte.ToString("x2"));
		}
		return destStrBuilder.ToString();
	}
}

参考

http://nanoappli.com/blog/archives/6347