1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
using UnityEngine;
using System;
using System.Collections;
using System.Security.Cryptography;
using System.Text;
public class CreateMD5 : MonoBehaviour
public string inputString;
public string hashString;
void Awake()
MD5 md5Hash = MD5.Create();
hashString = GetMD5Hash(md5Hash, inputString);
hashString = hashString.ToUpper();
private string GetMD5Hash(MD5 md5Hash, string input)
//Convert the input string to a byte array and compute the hash.
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
//Create a new StringBuilder to collect the bytes and create a string.
StringBuilder builder = new StringBuilder();
//Loop through each byte of the hashed data and format each one as a hexadecimal strings.
for(int cnt = 0; cnt < data.Length; cnt++)
builder.Append(data[cnt].ToString("x2"));
//Return the hexadecimal string
return builder.ToString();
private bool VerifyMD5Hash(MD5 md5Hash, string input, string hash)
//Hash the input
string hashOfInput = GetMD5Hash(md5Hash, input);
//Create a StringComparer to compare the hashes.
StringComparer comparer = StringComparer.OrdinalIgnoreCase;
return 0 == comparer.Compare(hashOfInput, hash);
|