~ruther/NosTale-Gfless

NosTale-Gfless/NostaleAuth/Utils/Cryptography.cs -rw-r--r-- 878 bytes
4f5eef52 — František Boháček chore: add license 4 years ago
                                                                                
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
using System.Security.Cryptography;
using System.Text;

namespace NostaleAuth.Utils
{
    public static class Cryptography
    {
        public static string ToMd5(string value)
        {
            using (var md5 = MD5.Create())
            {
                return Hash(value, md5);
            }
        }

        public static string ToSha512(string value)
        {
            using (var sha512 = SHA512.Create())
            {
                return Hash(value, sha512);
            }
        }
    
        private static string Hash(string value, HashAlgorithm hash)
        {
            byte[] bytes = hash.ComputeHash(Encoding.ASCII.GetBytes(value));
            var sb = new StringBuilder();
        
            foreach (byte b in bytes)
            {
                sb.Append(b.ToString("X2"));
            }
            return sb.ToString();
        }
    }
}
Do not follow this link