【发布时间】:2020-08-25 09:16:55
【问题描述】:
我正在开发一个需要连接到数据库的 Visual Studio 扩展包 (VSIX)。
我还想在存储敏感配置时采取合理的安全措施。
目前,我正在为我的插件使用标准的属性网格选项页面,如 introductory documentation 中所述用于 Visual Studio 扩展。
public class MyPackageOptions : DialogPage
{
[Category("Repository")]
[DisplayName("Server")]
[Description("Database host name or IP address")]
public String Server { get; set; }
[Category("Repository")]
[DisplayName("Port")]
[Description("Database listen port")]
public UInt16 Port { get; set; } = 3306;
[Category("Repository")]
[Description("Database name")]
public String Database { get; set; } = "default_database_name";
[Category("Repository")]
[DisplayName("User ID")]
[Description("Database login user name")]
public String UserId { get; set; }
// BUG PasswordPropertyTextAttribute doesn't seem to be having the desired effect
[Category("Repository")]
[Description("Database login password")]
[PasswordPropertyText]
public String Password { get; set; }
}
Category、DisplayName 和 Description 属性在属性网格显示上具有我所期望的效果。但是PasswordPropertyTextAttribute 似乎没有任何效果。是否有其他方法可以使文本屏蔽与基本的基于属性网格的选项页面一起使用?还是我需要制作自定义选项 UI 表单来获取文本屏蔽?
其次,我如何确保密码字段值以相当安全的方式保存在磁盘上,类似于其他需要存储用户凭据的软件?根据我的需要,我认为使用当前用户帐户的 Windows DPAPI 保护就足够了,但我不确定如何使用它来保护 MyPackageOptions.Password 属性。
【问题讨论】: