2012-09-04 20 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 

您需要雖然從服務器上運行此。