/// <summary> /// TODO: Comment /// </summary> public void SaveDataExcecute() { //TODO: Save path in configuration string configurationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SecureVault", "settings", "configuration.dat"); ConfigurationHelper configHelper = new ConfigurationHelper(configurationPath); SecureStringHelper secureStringHelper = new SecureStringHelper(); KeyHelper keyHelper = new KeyHelper(); SaltGenerator saltGenerator = new SaltGenerator(); //Generate random salt byte[] salt = saltGenerator.GenerateSalt(); byte[] key = keyHelper.DeriveKey(secureStringHelper.SecureStringToString(this.Password), configHelper.GetSalt()); CryptoHelper cryptoHelper = new CryptoHelper(key, salt); var plainTextBytes = Encoding.UTF8.GetBytes(secureStringHelper.SecureStringToString(this.SecureData)); var plainPasswordBase64 = Convert.ToBase64String(plainTextBytes); string encryptedValue = cryptoHelper.EncryptValue(plainPasswordBase64); configHelper.AddData(this.Name, encryptedValue, Convert.ToBase64String(salt)); //Close the NewData window Application.Current.Windows.OfType <Window>().SingleOrDefault(x => x.IsActive).Close(); }
private void CreateWallet() { if (null == Password || null == ConfirmPassword) { return; } var pwd = SecureStringHelper.SecureStringToString(Password); var confimrPwd = SecureStringHelper.SecureStringToString(ConfirmPassword); if (pwd != confimrPwd) { MessageBoxService.Show("两次输入的密码不匹配"); return; } this.IsCreating = true; var result = WalletManager.CreateWallet(pwd); this.MnemonicWords = string.Join(" ", result.MnemonicWords); this.IsCreating = false; this.IsCompleted = true; }
/// <summary> /// TODO: Comment /// </summary> public void SaveConfigurationExcecute() { string configurationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SecureVault", "settings", "configuration.dat"); ConfigurationHelper configHelper = new ConfigurationHelper(configurationPath); HashHelper hashHelper = new HashHelper(); SecureStringHelper secureStringHelper = new SecureStringHelper(); if (String.IsNullOrWhiteSpace(secureStringHelper.SecureStringToString(this.MasterPassword)) || String.IsNullOrWhiteSpace(secureStringHelper.SecureStringToString(this.MasterPasswordConfirmation))) { this.Error = "Please set a Password"; return; } //Check if password and confirmation are equal if (secureStringHelper.SecureStringToString(this.MasterPassword).Equals(secureStringHelper.SecureStringToString(this.MasterPasswordConfirmation))) { //Create configuration file configHelper.CreateConfigurationFile(); //Save master password string passwordHash = hashHelper.ComputeHash(secureStringHelper.SecureStringToString(this.MasterPassword)); configHelper.SaveMasterPassword(passwordHash); //Navigate to PasswordPage PasswordPage passwordPage = new PasswordPage(); passwordPage.DataContext = new PasswordViewModel(new Vault(), this.MainFrame); this.MainFrame.Navigate(passwordPage); } else { this.Error = "Not equal"; } }
private void Confirm() { if (null == this.Password) { return; } this.BtnContent = "提交中..."; var pwd = SecureStringHelper.SecureStringToString(Password); NetworkOperator.Instance.ChangeNetwork(CustomNetworkType.Regtest, RpcUrl, UserName, pwd); this.EventAggregator.GetEvent <ChangeNetworkEvent>().Publish(); this.BtnContent = "提交"; this.FinishInteraction?.Invoke(); }
private void Login() { if (null == this.Password) { return; } this.IsLogining = true; var pwd = SecureStringHelper.SecureStringToString(Password); bool status = WalletManager.Login(pwd); if (!status) { this.IsLogining = false; this.Msgbox.Show("密码错误"); return; } this._notification.Success = true; this.FinishInteraction?.Invoke(); }
/// <summary> /// TODO: Comment /// </summary> public void CopyPasswordExcecute(int?selectedID) { //TODO: Save path in configuration string configurationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SecureVault", "settings", "configuration.dat"); ConfigurationHelper configHelper = new ConfigurationHelper(configurationPath); KeyHelper keyHelper = new KeyHelper(); SecureStringHelper secureStringHelper = new SecureStringHelper(); selectedID = selectedID == -1 ? 0 : selectedID; byte[] key = keyHelper.DeriveKey(secureStringHelper.SecureStringToString(this.Password), configHelper.GetSalt()); CryptoHelper cryptoHelper = new CryptoHelper(key, Convert.FromBase64String(this.SavedData[selectedID.Value].Salt)); string decryptedValue = cryptoHelper.DecryptValue(this.SavedData[selectedID.Value].EncryptedValue); Clipboard.SetText(decryptedValue); }
/// <summary> /// TODO: Comment /// </summary> public void AuthenticateExcecute() { //TODO: Save path in configuration string configurationPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SecureVault", "settings", "configuration.dat"); ConfigurationHelper configHelper = new ConfigurationHelper(configurationPath); HashHelper hashHelper = new HashHelper(); SecureStringHelper secureStringHelper = new SecureStringHelper(); //Check if password is correct if (hashHelper.ComputeHash(secureStringHelper.SecureStringToString(this.Password)).Equals(configHelper.GetPasswordHash())) { IEnumerable <Tuple <string, string, string> > savedData = configHelper.GetAllSavedData(); ObservableCollection <SavedData> dataCollection = new ObservableCollection <SavedData>(); foreach (var data in savedData) { dataCollection.Add(new SavedData() { Name = data.Item1, EncryptedValue = data.Item2, Salt = data.Item3 }); } this.Model.SavedData = dataCollection; //Navigate to the VaultPage VaultPage vaultPage = new VaultPage(); vaultPage.DataContext = new VaultViewModel(this.Model); this.MainFrame.Navigate(vaultPage); } else { this.Error = "Invalid Password"; this.Model.SavedData = null; } }
private async void SignAndSendTx() { if ((PwdMethod && Password == null) || (PrivKeyMethod && string.IsNullOrWhiteSpace(PrivKey))) { return; } if (PwdMethod) { var pwd = SecureStringHelper.SecureStringToString(Password); await TxManager.SignAndSendUSDTTransaction(pwd, this.Transaction.ToHex(), this.SpentCoins, this.OperationId); } else { var keys = new List <string> { PrivKey, FeePrivKey }; await TxManager.SignAndSendTransactionByPrivateKey(keys, this.Transaction.ToHex(), this.SpentCoins, this.OperationId); } this.EventAggregator.GetEvent <TransactionCreated>().Publish(); this.FinishInteraction?.Invoke(); }
/// <summary> /// Authorizes a license key to check to see if it can be activated. If not, logs the failure reason and /// returns false. /// </summary> /// <param name="licenseKey"></param> /// <param name="licenseBase"></param> /// <param name="hardwareFingerprint"></param> /// <returns></returns> public bool AuthorizeLicenseForActivation(string licenseKey, ServiceLicense licenseBase, string hardwareFingerprint) { KeyData keyData = _licenseKeyService.GetLicenseKeyData(licenseKey, licenseBase, true); // Step 1: Validate the physical key bool keyValid = _licenseKeyService.ValidateLicenseKey(licenseKey, licenseBase, true); if (!keyValid) { _activationLogService.LogActiviation(licenseKey, ActivationResults.ValidationFailure, null); return(false); } SecureString hashedLicenseKey = SecureStringHelper.StringToSecureString(_hashingProvider.ComputeHash(licenseKey, Resources.KeyHashAlgo)); hashedLicenseKey.MakeReadOnly(); // Step 2: Validate the key against the service if (!DoesKeyExistForLicenseSet(SecureStringHelper.SecureStringToString(hashedLicenseKey), keyData.LicenseSetId)) { _activationLogService.LogActiviation(licenseKey, ActivationResults.UnknownKeyFailure, null); return(false); } // Step 3: Is this key used already if (!IsKeyAvialable(SecureStringHelper.SecureStringToString(hashedLicenseKey), keyData.LicenseSetId, hardwareFingerprint)) { _activationLogService.LogActiviation(licenseKey, ActivationResults.TooManyFailure, null); return(false); } return(true); }
/// <summary> /// Attempts to activate the license key /// </summary> /// <param name="licenseKey"></param> /// <param name="originalToken"></param> /// <param name="licenseBase"></param> /// <param name="hardwareFingerprint"></param> /// <returns></returns> public Guid?ActivateLicenseKey(string licenseKey, Guid?originalToken, ServiceLicense licenseBase, string hardwareFingerprint) { KeyData keyData = _licenseKeyService.GetLicenseKeyData(licenseKey, licenseBase, true); SecureString hashedLicenseKey = SecureStringHelper.StringToSecureString(_hashingProvider.ComputeHash(licenseKey, Resources.KeyHashAlgo)); hashedLicenseKey.MakeReadOnly(); int licenseSetId = keyData.LicenseSetId;// TODO: Only works for SSLK LicenseSet ls = _clientRepository.GetLicenseSetById(licenseSetId); LicenseActivation la = _clientRepository.GetLicenseActivationByKeyAndSetId(SecureStringHelper.SecureStringToString(hashedLicenseKey), licenseSetId); if (AuthorizeLicenseForActivation(licenseKey, licenseBase, hardwareFingerprint)) // TODO: Possible double call with two log entries here, as this is called in the parent as well. -SJ { ServiceLicenseKey lk = _serviceProductsRepository.GetServiceLicenseKeyByKeyLicenseSet(SecureStringHelper.SecureStringToString(hashedLicenseKey), licenseSetId); la = new LicenseActivation(); la.LicenseKeyId = lk.LicenseKeyId; la.ActivatedOn = DateTime.Now; la.ActivationToken = Guid.NewGuid(); la.OriginalToken = originalToken; la.ActivationStatus = ActivationStatus.Normal; la.ActivationStatusUpdatedOn = DateTime.Now; if (!String.IsNullOrEmpty(hardwareFingerprint)) { la.HardwareHash = hardwareFingerprint; } _clientRepository.InsertLicenseActivation(la); lk.ActivationCount++; _serviceProductsRepository.SaveServiceLicenseKey(lk); return(la.ActivationToken); } return(null); }