public string Load(string username) { var encryptString = default(string); username = username.Replace("ACTRANSIT\\", ""); try { var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); //var currentUser = WindowsIdentity.GetCurrent().Name; var userKey = rootKey + "\\" + username; var rk = baseKey.OpenSubKey( userKey, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey); encryptString = rk.GetValue(null) as string; rk.Close(); baseKey.Close(); } catch (Exception e) { return(e.Message); } var service = new AesEncryptionService(key, IV); var decryptString = DecodeBase(service.DecryptString(encryptString)); return(decryptString); }
public bool Save(string username, string password) { username = username.Replace("ACTRANSIT\\", ""); var service = new AesEncryptionService(key, IV); var encryptString = service.EncryptString(EncodeBase(password)); //var currentUser = WindowsIdentity.GetCurrent().Name; var userKey = rootKey + "\\" + username; RegistryKey baseKey = null; RegistryKey rk = null; try { baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); if (baseKey == null) { return(false); } rk = baseKey.OpenSubKey( userKey, RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryRights.ReadKey | RegistryRights.SetValue); //setupRegKeyRights(currentUser, baseKey); } catch // (Exception e) { } if (rk == null) { return(false); } try { rk.SetValue(null, encryptString); } catch //(Exception e) { return(false); } finally { rk.Close(); baseKey.Close(); } return(true); }