简体   繁体   English

保护ConnectionString

[英]Securing a ConnectionString

i want to secure a connectionstring so it is not possible to "read" it out for any purpose. 我想确保连接字符串安全,因此无法出于任何目的“读取”它。

at the moment i'm doing it like this and i know it is like the Windows Firewall, open in all directions... 目前我正在这样做,我知道它就像Windows防火墙一样,可以全方位打开...

private static string connStr = "server=localhost;user=MySuperSecretUser;database=MySuperSecretDatabase;port=3306;password=MySuperSecretPassword;sslMode=none;";
private static MySqlConnection conn = new MySqlConnection(connStr);
private static MySqlConnection conn2 = new MySqlConnection(connStr);

does anybody know how i can secure it so nobody is able to help me out here? 有人知道我如何保护它,所以没人能在这里帮助我吗?

If you are using standard .Net. 如果您使用的是标准.Net。 Follow below steps for encrypting the Connection String 请按照以下步骤加密连接字符串

Encrypting Web.Config 加密Web.Config

Step 1 Open Command Prompt with Administrator privileges 步骤1使用管理员权限打开命令提示符

Step 2 At the Command Prompt, enter below command 步骤2在命令提示符处,输入以下命令

cd C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319 cd C:\\ Windows \\ Microsoft.NET \\ Framework \\ v4.0.30319

Step 3: 第三步:

In case your web Config is located in "D:\\Articles\\EncryptWebConfig" directory path, then enter the following to encrypt the ConnectionString. 如果您的Web Config位于“ D:\\ Articles \\ EncryptWebConfig”目录路径中,请输入以下内容以加密ConnectionString。 Please note that ConnectionString is case sensitive 请注意,ConnectionString 区分大小写

ASPNET_REGIIS -pef "connectionStrings" "D:\\Articles\\EncryptWebConfig" ASPNET_REGIIS -pef“ connectionStrings”“ D:\\ Articles \\ EncryptWebConfig”

Accessing Decrypted Configuration Settings 访问解密的配置设置

ASP.NET automatically decrypts the contents of the Web.Config file when it processes the file. ASP.NET在处理文件时会自动解密Web.Config文件的内容。 Therefore, no additional steps are required to decrypt the encrypted configuration settings. 因此,不需要其他步骤即可解密加密的配置设置。

string ConnString = ConfigurationManager.ConnectionStrings[1].ToString(); 字符串ConnString = ConfigurationManager.ConnectionStrings [1] .ToString();

You can encrypt it, but if your code can use it, someone with access to the code can also decrypt it. 您可以对其进行加密,但是如果您的代码可以使用它,则有权访问该代码的人也可以对其进行解密。

The solution I've seen is for the developers to restrict access to the code, and for the server admin team to restrict access to the config files. 我见过的解决方案是,开发人员限制对代码的访问,服务器管理员团队限制对配置文件的访问。

The server admin team (who already know this information) use the encryption tool to set up the config file on the web server. 服务器管理员团队(已经知道此信息)使用加密工具在Web服务器上设置配置文件。 The programmers can't access the config file and any hacker that reads the config file can't decrypt it. 程序员无法访问该配置文件,并且任何读取该配置文件的黑客都无法解密该文件。

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

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