Alvin
Alvin

Reputation: 8519

Ecrypt password in app.config

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

Answers (3)

Vishal Suthar
Vishal Suthar

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

Nick Jones
Nick Jones

Reputation: 6493

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

Upvotes: 1

Rodders
Rodders

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

Related Questions