简体   繁体   English

C#安全地将密码另存为字符串以进行Oracle数据库连接吗?

[英]C# Saving password as string safely for Oracle Database connection?

I am trying to connect to Oracle database using ODP.net in C#. 我正在尝试使用C#中的ODP.net连接到Oracle数据库。

string myuserid;
string mypw;
string connstring =
  "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhost)(PORT=1527))" +
  "(CONNECT_DATA=(SID=mysid)));User Id=" + myuserid + ";Password=" + mypw + ";";
using (OracleConnection conn = new OracleConnection(connstring))

I want to use windows form to get myuserid and mypw to use it in a query. 我想使用Windows窗体获取myuserid和mypw以便在查询中使用它。

What would be the best way to store this information during the session securely? 在会话期间安全地存储此信息的最佳方法是什么? Is it possible to remove this string after certain time of inactivity? 在一段时间不活动之后是否可以删除此字符串?

Thank you in advance.. 先感谢您..

You can use ProtectedData.Protect to encrypt data in a way that is tied to the local user profile (ie. will only work for the current user on the current machine). 您可以使用ProtectedData.Protect以与本地用户配置文件关联的方式加密数据(即,仅适用于当前计算机上的当前用户)。

This can then be saved locally, and then passed through ProtectedData.Unprotect to get the password back to build a new connection string. 然后可以将其保存在本地,然后通过ProtectedData.Unprotect传递回密码以建立新的连接字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM