Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6979923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:56:52+00:00 2026-05-27T17:56:52+00:00

Scenario: I have a WPF desktop application which will be distributed on different machines

  • 0

Scenario:
I have a WPF desktop application which will be distributed on different machines for different customers.
The application has an XML configuration file ‘ApplicationConfiguration.xml’
This XML file contains connection strings.
I need to encrypt these connection strings as the ApplicationConfiguration.xml file will be copied to the installation folder of the application along with the main application exe.

Planned Strategy :
My planned strategy was to encrypt the ‘ApplicationConfiguration.xml’ file after the installation. ( If I could do it during the installation then all the better )

What I have tried :
Going with the strategy of encrypting the xml file AFTER installation I decided to write a simple winforms application to allow the user to browse for the ‘ApplicationConfiguration.xml’ and simply press a button to encrypt it.
When I did this, I got a new file created in the form of an xml Configuration File.
‘ApplicationConfiguration.xml.Config’, but the original ‘ApplicationConfiguration.xml’ file still remained intact with the connection strings untouched…
Now…. when i copied the contents of this file into my ‘ApplicationConfiguration.xml’ file the program was able to function as normal … the xml is now encrypted remember.
So it appears that the .NET 4.0 framework can DECRYPT the xml file without me having to write anymore code in my WPF application.

See code below to do the encryption:

   protected void EncryptConfig(Boolean bEncrypt)
    {
        string path = SelectedFilePath();

        Configuration config = ConfigurationManager.OpenExeConfiguration(path);

        // Define the Rsa provider name. 

        const string provider = "RsaProtectedConfigurationProvider";

        // Get the section to protect. 

        ConfigurationSection connStrings = config.ConnectionStrings;

        if (connStrings != null)
        {
            if (!connStrings.SectionInformation.IsProtected)
            {
                if (!connStrings.ElementInformation.IsLocked)
                {
                    // Protect the section.             
                    connStrings.SectionInformation.ProtectSection(provider);
                    connStrings.SectionInformation.ForceSave = true;
                    config.Save(ConfigurationSaveMode.Full);
                }
            }
        }

        MessageBox.Show("Config has been encrypted");
}

I have posted example output ( Replacing the CipherData with dummy characters ) which is created by the code above

    <?xml version="1.0" encoding="utf-8"?>
 <configuration>    
<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>skfjshsadfhsadkjfsadhfsadkhfdsafhsadkfhkljdfh=</CipherValue>
                </CipherData>
            </EncryptedKey>
        </KeyInfo>
        <CipherData>
            <CipherValue>adfdsafdsafdsfdsafsadfsadfsadfsdfasfdsadfsafsadfdsf=</CipherValue>
        </CipherData>
    </EncryptedData>
</connectionStrings>

So I have a few questions on what I have done above and what I am trying to do :

1) Can the application read the encrypted connection strings without writing new code in the WPF application ? And if so, will each machine be able to read the encrypted connection strings if I do all the encryption processing on my own machine? As I have read about the ‘Key’ required.. and dont understand where the keyName above ( Rsa Key ) comes from.

2) Why when I save the xml file in my above code example is there a new ‘xml.config’ file created? Should I be manually copying the newly generated code into the original applicationConfiguration.xml file?

Just to add, when I decrypt the new xml.config file using the following code:

       connStrings.SectionInformation.UnprotectSection();
                config.Save(ConfigurationSaveMode.Full);

.. I get the following output ! WHY! 🙂

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
    <clear />
    <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
        providerName="System.Data.SqlClient" />
</connectionStrings>
    </configuration>

I would have expected to get my original 3 connection strings… no?

Basically I am looking for the correct method to proceed with encrypting an xml file of connection strings and allow the application to be deployed and read on different machines.

Any help appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:56:53+00:00Added an answer on May 27, 2026 at 5:56 pm

    See .Net Encryption – Dataprotection API is no help here, you would need to send it unencrypted to have it locally encrypted to the machine / user key.

    At best you can use any of the available encryption classes to encrypt it to a key stored within your app and hope nobody disassembles your software.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: I have a text file that has pipe (as in the | character)
I have a desktop client application build under .net 4.0 and WPF. In this
Consider this scenario; suppose I have WPF window which have four objects bonded to
Here's the scenario. We use a large XML configuration file for one of our
Following scenario: In an WPF application the program calls Log.Write to enqueue messages which
The following scenario bothers me: I have a simple WPF Window that has a
Consider a scenario where I have a WebBrowser Control in WPF application. A web
Scenario: I have a console application that needs to access a network share with
I have a WPF application using MVVM. I have some user controls that show
I have a small WPF application that I am working on localizing. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.