Reputation: 8519
I am using Entity Framework
to create a SQLServer connection of database with a password:
connectionString="DataSource=|DataDirectory|DB.sdf;Password=abc
How can I protect the password while using Entity Framework?
Upvotes: 0
Views: 1601
Reputation: 17194
You can write EncDecHelper.Decrypt
by using samples from here: Encrypt/Decrypt string in .NET
You will find the related information from here: Encrypt password in App.config
Upvotes: 0
Reputation: 6493
ConnectionStringsSection oSection = Configuration.ServiceConfiguration.GetConnectionStrings();
if(!oSection.SectionInformation.IsLocked && !oSection.SectionInformation.IsProtected)
{
oSection.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider");
oSection.CurrentConfiguration.Save();
}
Upvotes: 1
Reputation: 2435
If you have access to the server, you can use the web config encryption tool from cmd. I create a .bat file in the same folder as my web.config containing:
aspnet_regiis -pef connectionStrings .
aspnet_regiis -pef appSettings .
pause
This will encrypt the connectionStrings whole section and in my case, the appSettings whole section too.
To Decrypt, do:
aspnet_regiis -pdf connectionStrings .
aspnet_regiis -pdf appSettings .
pause
You will need to run this from the server though.
Upvotes: 0