2012-09-04 28 views
0

我使用Entity Framework创建数据库的具有密码的SQLServer的连接:ECRYPT密码的app.config

connectionString="DataSource=|DataDirectory|DB.sdf;Password=abc 

如何保护密码,而使用实体框架?

回答

1
ConnectionStringsSection oSection = Configuration.ServiceConfiguration.GetConnectionStrings(); 
    if(!oSection.SectionInformation.IsLocked && !oSection.SectionInformation.IsProtected) 
    { 
     oSection.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider"); 
     oSection.CurrentConfiguration.Save(); 
    } 
+0

是否与实体框架这项工作,因为上面的代码将加密连接字符串。 – Alvin

0

如果您有权访问服务器,则可以使用cmd中的Web配置加密工具。我创建在同一文件夹.bat文件作为包含我的web.config:

aspnet_regiis -pef connectionStrings . 
aspnet_regiis -pef appSettings . 
pause 

这将加密的ConnectionStrings整段,在我的情况下,整体的appSettings节了。

解密,这样做:

aspnet_regiis -pdf connectionStrings . 
aspnet_regiis -pdf appSettings . 
pause 

您需要虽然从服务器上运行此。