private byte[] KeyStoreDecrypt(PasswordRegistryTypes passwordIdentifier, string json) { var tries = 0; while (tries < MaxTries) { var securePassword = _passwordManager.RetrieveOrPromptPassword(passwordIdentifier, "Please provide your node password"); var password = StringFromSecureString(securePassword); try { var keyBytes = DecryptKeyStoreFromJson(password, json); if (keyBytes != null && keyBytes.Length > 0) { _passwordManager.AddPasswordToRegistry(passwordIdentifier, securePassword); return(keyBytes); } } catch (DecryptionException) { securePassword.Dispose(); _logger.Error("Error decrypting keystore"); } tries += 1; } throw new AuthenticationException("Password incorrect for keystore."); }
/// <inheritdoc /> public SecureString RetrieveOrPromptPassword(PasswordRegistryTypes passwordType, string promptMessage = null) { var password = _passwordRegistry.GetItemFromRegistry(passwordType) ?? _passwordReader.ReadSecurePassword(promptMessage ?? $"Please enter your {passwordType.Name}"); return(password); }
public static void AddPassword(PasswordRegistry passwordRegistry, PasswordRegistryTypes passwordRegistryTypes, string password) { var secureString = new SecureString(); foreach (var character in password) { secureString.AppendChar(character); } passwordRegistry.AddItemToRegistry(passwordRegistryTypes, secureString); }
/// <inheritdoc /> public SecureString RetrieveOrPromptAndAddPasswordToRegistry(PasswordRegistryTypes passwordType, string promptMessage = null) { var password = RetrieveOrPromptPassword(passwordType, promptMessage ?? $"Please enter your {passwordType.Name}"); if (password != null) { _passwordRegistry.AddItemToRegistry(passwordType, password); } return(password); }
public Kernel WithPassword(PasswordRegistryTypes types, string password) { if (password == null) { return(this); } ContainerBuilder.RegisterBuildCallback(buildCallback => { var passwordRegistry = buildCallback.Resolve <IPasswordRegistry>(); var ss = new SecureString(); foreach (var c in password) { ss.AppendChar(c); } passwordRegistry.AddItemToRegistry(types, ss); }); return(this); }
/// <inheritdoc /> public bool AddPasswordToRegistry(PasswordRegistryTypes passwordType, SecureString password) { return(_passwordRegistry.AddItemToRegistry(passwordType, password)); }