daily pastebin goal
42%
SHARE
TWEET

local password save

tolikpunkoff May 5th, 2018 (edited) 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Security.Cryptography;
  2. //[...]
  3. private byte[] GetEntropy(string EntropyString)
  4. {
  5.  
  6.     MD5 md5 = MD5.Create();
  7.     return md5.ComputeHash(Encoding.UTF8.GetBytes(EntropyString));
  8. }
  9.  
  10. private bool EncryptPassword()
  11. {
  12.     if (string.IsNullOrEmpty(ProxyPassword)) return true;
  13.     if (string.IsNullOrEmpty(ProxyAddress) || string.IsNullOrEmpty(ProxyUser))
  14.         return false;
  15.  
  16.     byte[] entropy = GetEntropy(ProxyAddress + ProxyUser);
  17.     byte[] pass = Encoding.UTF8.GetBytes(ProxyPassword);
  18.     byte[] crypted=ProtectedData.Protect(pass,
  19.         entropy, DataProtectionScope.LocalMachine);
  20.     ProxyPassword = Convert.ToBase64String(crypted);
  21.  
  22.     return true;
  23. }
  24.  
  25. private bool DecryptPassword()
  26. {
  27.     if (string.IsNullOrEmpty(ProxyPassword)) return true;
  28.     if (string.IsNullOrEmpty(ProxyAddress) || string.IsNullOrEmpty(ProxyUser))
  29.         return false;
  30.                    
  31.     byte[] pass = null;
  32.     try
  33.     {
  34.         pass = Convert.FromBase64String(ProxyPassword);
  35.     }
  36.     catch (Exception ex)
  37.     {
  38.         ConfigError = ex.Message;
  39.         return false;
  40.     }
  41.     byte[] entropy = GetEntropy(ProxyAddress + ProxyUser);
  42.  
  43.     try
  44.     {
  45.         pass = ProtectedData.Unprotect(pass, entropy, DataProtectionScope.LocalMachine);
  46.     }
  47.     catch (Exception ex)
  48.     {
  49.         ConfigError = ex.Message;
  50.         return false;
  51.     }
  52.     ProxyPassword = Encoding.UTF8.GetString(pass);                
  53.    
  54.     return true;
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top