· 7 years ago · Sep 05, 2018, 07:20 AM
1Hash Function .NET
2string GetEncodedHash(string password, string salt)
3{
4 MD5 md5 = new MD5CryptoServiceProvider();
5 byte [] digest = md5.ComputeHash(Encoding.UTF8.GetBytes(password + salt);
6 string base64digest = Convert.ToBase64String(digest, 0, digest.Length);
7 return base64digest.Substring(0, base64digest.Length-2);
8}
9
10string secretKey = "MySecretKey";
11string salt = "123";
12System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1.Create();
13byte[] preHash = System.Text.Encoding.UTF32.GetBytes(secretKey + salt);
14byte[] hash = sha.ComputeHash(preHash);
15string password = prefix + System.Convert.ToBase64String(hash, 0, 15);