Exception thrown on Encrypting web.config connectionStrings using aspnet_regiis.exe

179 Views Asked by At

I have a .net web application created using mvc entity framework.I encrypted the connectionStrings section inside aspnet_regiis.exe using developer command prompt.Following command is used for encryption :

aspnet_regiis.exe -pef "connectionStrings" "C:\..webconfig path.."

The above code encrypts the connection string section inside web.config.But it throws an exception as follows:

ConfigurationErrorsException: The RSA key container could not be opened. The error is thrown inside the following code:

public DataContext()
            : base("LEAContext")
        {
            Database.SetInitializer(new Seeder());
            Configuration.ProxyCreationEnabled = false;
        }

Connection string before encryption:

 <connectionStrings>
    <add name="LEAContext" connectionString="Data Source=.\SQLExpress;Database=LEADbServer;User ID=sa;Password=pwd@123" providerName="System.Data.SqlClient" providerName="System.Data.SqlClient" />
  </connectionStrings>

Connection String After encryption :

<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
    <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
      xmlns="http://www.w3.org/2001/04/xmlenc#">
      <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
      <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
        <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
          <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
          <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
            <KeyName>Rsa Key</KeyName>
          </KeyInfo>
          <CipherData>
            <CipherValue>HRY3gmulN8MhNrCehjWyoBH600bGtLm0km1TvV7fCGPZjQHnST6mJ6YU4UWUr300Y9BPfhh/bwyMR2sa5zNnN4sT/XiUOCKJ6a3YvKg3LBEA/DmTWiFow5F9JllyP3OO1271l9uEuEuYcVdovqf7D3s4DWupGGi6MxFjl9tQe89HjKcvgiLYTQQp0jmFDdjcBWaXuk7ad5FENsgpTdAdUQk3zlneiq1X6NzqoA9S5v87qKIqUTwcJ6TfWvowcGqkQAh13IqtegbDwci22eoYvT/kVmsOYW38/IrHn1eaw4ZqlfH5hXJMJda9AWNyqvoYd2JILMZzZ/lHGCClfUAMlg==</CipherValue>
          </CipherData>
        </EncryptedKey>
      </KeyInfo>
      <CipherData>
        <CipherValue>abpT46oFCWxOsJ5UTkg9WAZCrYoVlQ5fRn6RqtDgQ1udN+wmWbECnBMMxftR1Zthn2NJ2Nq546Q+7z9pyaQ9bE8oczbdOYY8g7FqWvkQbPr0f4vmsXCZGgJwa0TaCT8k82CAuRTh7oo9QZOnGPoEdV8KaB1hXwDWLQkx8y5F59FdQemwZButRd/bOXg9M3yG7qF/u4i3bH5iATYVNBzSZXn7saR1ltTooQNolIxe5RD4fR3XnpYauJfu40ag97UHeQcle+I39hKp0OS/PStBctJAg0bUa1C+</CipherValue>
      </CipherData>
    </EncryptedData>
  </connectionStrings>
0

There are 0 best solutions below