Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypt Web.config Windows Azure

Tags:

azure

I am using a shared website from Windows Azure. I would like to encrypt parts of my web.config, however, I get this error:

Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: The RSA key container could not be opened.

I have a page in my site that will encrypt that file and it does, however, after a few hours I get this error. Do I need to send my machine key over to Azure or do they have one I can use?

To encrypt my config file, I use this code:

    /// <summary>
    /// About view for the website.
    /// </summary>
    /// <returns>Action Result.</returns>
    public ActionResult About()
    {
        Configuration objConfig =
          WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
        AppSettingsSection objAppsettings =
          (AppSettingsSection)objConfig.GetSection("appSettings");
        if (!objAppsettings.SectionInformation.IsProtected)
        {
            objAppsettings.SectionInformation.ProtectSection(
                           "RsaProtectedConfigurationProvider");
            objAppsettings.SectionInformation.ForceSave = true;
            objConfig.Save(ConfigurationSaveMode.Modified);
        }

        return View();
    }
like image 775
Joseph Anderson Avatar asked Feb 22 '13 14:02

Joseph Anderson


People also ask

How do I encrypt an entire web config file?

Encrypting a Web Configuration Section To encrypt configuration file contents, use the Aspnet_regiis.exe tool with the –pe option and the name of the configuration element to be encrypted. Use the –app option to identify the application for which the Web.


1 Answers

It might not be exactly what you are looking for, but you could use the Configuration tab in the Azure dashboard to overwrite the AppSettings at runtime so the web.config doesn't store any actual sensitive data.

http://www.windowsazure.com/en-us/manage/services/web-sites/how-to-configure-websites/#howtochangeconfig

App Settings – Specify name/value pairs that will be loaded by your web application on start up. For .NET sites, these settings will be injected into your .NET configuration AppSettings at runtime, overriding existing settings. For PHP and Node sites these settings will be available as environment variables at runtime.

like image 57
ryanbillingsley Avatar answered Oct 06 '22 22:10

ryanbillingsley