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












1















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>









share|improve this question



























    1















    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>









    share|improve this question

























      1












      1








      1








      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>









      share|improve this question














      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>






      c# asp.net-mvc-5 aspnet-regiis.exe






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 9:41









      swaroop josephswaroop joseph

      547




      547
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53478313%2fexception-thrown-on-encrypting-web-config-connectionstrings-using-aspnet-regiis%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53478313%2fexception-thrown-on-encrypting-web-config-connectionstrings-using-aspnet-regiis%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)