【问题标题】:secure connection to the server mysql - C #安全连接到服务器 mysql - C#
【发布时间】:2014-12-07 03:34:14
【问题描述】:
我对与数据库的安全连接有疑问。
我使用 app.config 文件与 MySql 数据库建立了连接,我在其中放置了数据服务器、数据库和用户密码。
所谓的连接字符串。安全吗?
请提供帮助并提供任何提示或任何好的材料。
示例代码:
<connectionStrings>
<add
name="MyDBConnectionString"
connectionString="NameServer.info; User Id=NameUser; Persist Security Info=True; database=DatabaseName; password=Pass"
providerName="MySql.Data.MySqlClient"
/>
</connectionStrings>
【问题讨论】:
标签:
c#
mysql
database
security
connection
【解决方案1】:
您应该加密存储在配置文件中的Connection Strings。
使用在以下位置找到的 aspnet_regiis.exe:开始 -> Visual Studio -> Visual Studio 工具 -> Visual Studio 命令提示符
运行这个命令:
aspnet_regiis –pef connectionStrings c:\PathToWebSite
如果上面的命令不起作用试试
aspnet_regiis -pe connectionStrings -app "/" -site n
其中n 是 IIS 中报告的网站的站点 ID。
现在,如果您的 Connection String 部分将被加密:
<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>Bf677iFrUFW ... +4n4ZZKXCTUAu2Y=</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>UDEZ ...QfXUmM5rQ==</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
更多信息: