added client server login with hashed passwords and usernames
This commit is contained in:
@@ -7,45 +7,21 @@ namespace Hashing
|
||||
{
|
||||
class Hasher
|
||||
{
|
||||
static string key = "ProftaakRH-B4";
|
||||
public static string Encrypt(string text)
|
||||
public static byte[] GetHash(string input)
|
||||
{
|
||||
using (var md5 = new MD5CryptoServiceProvider())
|
||||
using (HashAlgorithm algorithm = SHA256.Create())
|
||||
{
|
||||
using (var tdes = new TripleDESCryptoServiceProvider())
|
||||
{
|
||||
tdes.Key = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
|
||||
tdes.Mode = CipherMode.ECB;
|
||||
tdes.Padding = PaddingMode.PKCS7;
|
||||
|
||||
using (var transform = tdes.CreateEncryptor())
|
||||
{
|
||||
byte[] textBytes = UTF8Encoding.UTF8.GetBytes(text);
|
||||
byte[] bytes = transform.TransformFinalBlock(textBytes, 0, textBytes.Length);
|
||||
return Convert.ToBase64String(bytes, 0, bytes.Length);
|
||||
}
|
||||
}
|
||||
return algorithm.ComputeHash(Encoding.UTF8.GetBytes(input));
|
||||
}
|
||||
}
|
||||
|
||||
public static string Decrypt(string cipher)
|
||||
public static string HashString(string input)
|
||||
{
|
||||
using (var md5 = new MD5CryptoServiceProvider())
|
||||
{
|
||||
using (var tdes = new TripleDESCryptoServiceProvider())
|
||||
{
|
||||
tdes.Key = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
|
||||
tdes.Mode = CipherMode.ECB;
|
||||
tdes.Padding = PaddingMode.PKCS7;
|
||||
|
||||
using (var transform = tdes.CreateDecryptor())
|
||||
{
|
||||
byte[] cipherBytes = Convert.FromBase64String(cipher);
|
||||
byte[] bytes = transform.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length);
|
||||
return UTF8Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (byte b in GetHash(input)) {
|
||||
sb.Append(b.ToString("X2"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user