Рефакторинг + DI

This commit is contained in:
Danil Kislov
2019-03-15 17:49:58 +03:00
parent fd02201b42
commit d56094febb
19 changed files with 288 additions and 105 deletions
@@ -0,0 +1,42 @@
using System;
using System.Security.Cryptography;
using System.Text;
namespace JiraTimeBotForm.Configuration
{
public class PasswordEncryptionClass
{
private byte[] GetEntropy(string EntropyString)
{
MD5 md5 = MD5.Create();
return md5.ComputeHash(Encoding.UTF8.GetBytes(EntropyString));
}
public string Encrypt(string username, string password, string address)
{
byte[] entropy = GetEntropy(address + username);
byte[] pass = Encoding.UTF8.GetBytes(password);
byte[] crypted = ProtectedData.Protect(pass, entropy, DataProtectionScope.LocalMachine);
var cryptedBase64 = Convert.ToBase64String(crypted);
return cryptedBase64;
}
public string Decrypt(string username, string password, string address)
{
try
{
var pass = Convert.FromBase64String(password);
byte[] entropy = GetEntropy(address + username);
pass = ProtectedData.Unprotect(pass, entropy, DataProtectionScope.LocalMachine);
return Encoding.UTF8.GetString(pass);
}
catch (Exception ex)
{
return "";
}
}
}
}