2014-10-12 142 views
0

我对安全连接到数据库有疑问。 我使用app.config文件与MySql数据库建立连接,在该文件中放置数据服务器,数据库和用户密码。 所谓的connectionString。它安全吗?安全连接到服务器mysql-C#

请帮助,并有任何提示或任何好的材料。

示例代码:

<connectionStrings> 
    <add 
     name="MyDBConnectionString" 
     connectionString="NameServer.info; User Id=NameUser; Persist Security Info=True; database=DatabaseName; password=Pass" 
     providerName="MySql.Data.MySqlClient" 
    /> 
</connectionStrings> 

回答

0

你应该加密您的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> 

欲了解更多信息: