我想创建一个C#WinForms应用程序,它将向需要用户名和密码的服务器创建Web请求(基本身份验证) .
我想在运行应用程序的计算机上本地保存密码(当然是加密的) .
基本上,我需要在iOS中作为Keychain运行的东西,或在eclipse中作为“安全存储”运行,仅适用于.NET
我在Windows中找到了Credential Manager,但所有API示例都来自.NET Framework V2.0
微软是否有关于如何在C#中使用它的普通API?
Windows应用程序可以使用DPAPI,数据保护API在计算机上存储机密,并通过用户's login credentials. Any process that runs with the user'权限加密(间接)可以访问此数据 . 或者,如果您愿意,可以让用户添加自己的密码(对于这一项/秘密)(PrompStruct) . DPAPI也可以通过C#访问(网上有例子) .
您可以将凭据存储在app.config中的一个部分中,然后对该部分进行加密(类似于您在web.config中为Web应用程序执行的操作) .
您可以使用SectionInformation.ProtectSection来保护该部分,使用SectionInformation.GetRawXml来检索加密信息(解密是透明地完成的) .
示例(摘自下面的MSDN文章):
static public void ProtectSection() { // Get the current configuration file. System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); // Get the section. UrlsSection section = (UrlsSection)config.GetSection("MyUrls"); // Protect (encrypt)the section. section.SectionInformation.ProtectSection( "RsaProtectedConfigurationProvider"); // Save the encrypted section. section.SectionInformation.ForceSave = true; config.Save(ConfigurationSaveMode.Full); // Display decrypted configuration // section. Note, the system // uses the Rsa provider to decrypt // the section transparently. string sectionXml = section.SectionInformation.GetRawXml(); Console.WriteLine("Decrypted section:"); Console.WriteLine(sectionXml); }
http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.protectsection.aspx
2 回答
Windows应用程序可以使用DPAPI,数据保护API在计算机上存储机密,并通过用户's login credentials. Any process that runs with the user'权限加密(间接)可以访问此数据 . 或者,如果您愿意,可以让用户添加自己的密码(对于这一项/秘密)(PrompStruct) . DPAPI也可以通过C#访问(网上有例子) .
您可以将凭据存储在app.config中的一个部分中,然后对该部分进行加密(类似于您在web.config中为Web应用程序执行的操作) .
您可以使用SectionInformation.ProtectSection来保护该部分,使用SectionInformation.GetRawXml来检索加密信息(解密是透明地完成的) .
示例(摘自下面的MSDN文章):
http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.protectsection.aspx