c# - 在 C# 控制台应用程序 app.config 中嵌入 webclient 的凭据?

标签 c# .net webclient app-config networkcredentials

目前我正在使用这样的登录方法登录,但我想将其嵌入到 app.config 文件中以便安全保存......

目前看起来是这样的。

WebClient c = new WebClient();  
c.Credentials = new System.Net.NetworkCredential("UN", "PW", "server");

如何将其嵌入到 app.config 文件中???

最佳答案

<appSettings>
  <add key="NetworkCredentialUserName" value="UN" />
  <add key="NetworkCredentialPassword" value="PW" />
</appSettings>

然后

var networkCredentialUserName = ConfigurationManager.AppSettings["NetworkCredentialUserName"];
var networkCredentialPassword = ConfigurationManager.AppSettings["NetworkCredentialPassword"];
c.Credentials = new System.Net.NetworkCredential(networkCredentialUserName, networkCredentialPassword , "server");

然而,这并不能使它们安全。如果网络凭据用户名和密码敏感,我会考虑使用 PKCS12ProtectedConfigurationProvider(一个 nuget 包)之类的东西加密 app.config appSettings 部分。

关于c# - 在 C# 控制台应用程序 app.config 中嵌入 webclient 的凭据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30574657/

相关文章:

c# - GDI+ 中发生一般性错误(屏幕截图 SaveAsFile、ExternalException)

c# - 使用 SSH.Net 将 GzipStream 上传到 SFTP

c# - int.TryParse = null 如果不是数字?

c# - 如何将 `null` 转换为可空 int?我总是得到0

.NET WebClient : Where is DownloadString?

c# - 指向 Byte[] 数组的不安全 Int32 指针

c# - 从列表中的数组中删除对象

C# WebClient 内存使用

时间:2019-03-17 标签:c#asyncwebclient

c# - 如何公开 UserControl 的 Text 属性?