Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Security.Cryptography;
- //[...]
- private byte[] GetEntropy(string EntropyString)
- {
- MD5 md5 = MD5.Create();
- return md5.ComputeHash(Encoding.UTF8.GetBytes(EntropyString));
- }
- private bool EncryptPassword()
- {
- if (string.IsNullOrEmpty(ProxyPassword)) return true;
- if (string.IsNullOrEmpty(ProxyAddress) || string.IsNullOrEmpty(ProxyUser))
- return false;
- byte[] entropy = GetEntropy(ProxyAddress + ProxyUser);
- byte[] pass = Encoding.UTF8.GetBytes(ProxyPassword);
- byte[] crypted=ProtectedData.Protect(pass,
- entropy, DataProtectionScope.LocalMachine);
- ProxyPassword = Convert.ToBase64String(crypted);
- return true;
- }
- private bool DecryptPassword()
- {
- if (string.IsNullOrEmpty(ProxyPassword)) return true;
- if (string.IsNullOrEmpty(ProxyAddress) || string.IsNullOrEmpty(ProxyUser))
- return false;
- byte[] pass = null;
- try
- {
- pass = Convert.FromBase64String(ProxyPassword);
- }
- catch (Exception ex)
- {
- ConfigError = ex.Message;
- return false;
- }
- byte[] entropy = GetEntropy(ProxyAddress + ProxyUser);
- try
- {
- pass = ProtectedData.Unprotect(pass, entropy, DataProtectionScope.LocalMachine);
- }
- catch (Exception ex)
- {
- ConfigError = ex.Message;
- return false;
- }
- ProxyPassword = Encoding.UTF8.GetString(pass);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement