-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHashAlgorithm.cs
More file actions
31 lines (28 loc) · 937 Bytes
/
HashAlgorithm.cs
File metadata and controls
31 lines (28 loc) · 937 Bytes
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
using System.Security.Cryptography;
using System.Text;
namespace KetamaHash
{
internal class HashAlgorithm
{
public static long hash(byte[] digest, int nTime)
{
long rv = ((long)(digest[3 + nTime * 4] & 0xFF) << 24)
| ((long)(digest[2 + nTime * 4] & 0xFF) << 16)
| ((long)(digest[1 + nTime * 4] & 0xFF) << 8)
| ((long)digest[0 + nTime * 4] & 0xFF);
return rv & 0xffffffffL; // Truncate to 32-bits
}
/// <summary>
/// Get the md5 of the given key.
/// </summary>
/// <param name="k"></param>
/// <returns></returns>
public static byte[] computeMd5(string k)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] keyBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(k));
md5.Clear();
return keyBytes;
}
}
}