Skip to content

C# - WPF - Encyption and Decryption Connection String in Runtime with Visual Studio Installer Projects. [Year of Development: 2018]

Notifications You must be signed in to change notification settings

Sullivan008/CSharp-WPF-EncryptionDecryptionConnString

Repository files navigation

C# - WPF - Encyption and Decryption Connection String in Runtime with Visual Studio Installer Projects. [Year of Development: 2018]

About the application technologies and operation:

Technologies:

  • Programming Language: C#
  • FrontEnd Side: Windows Presentation Foundation (WPF) - .NET Framework 4.6.1
  • BackEnd Side: .NET Framework 4.6.1.
  • Other used modul:
    • Visual Studio Installer Projects.

Installation/ Configuration:

  1. Restore necessary Packages on the selected project, run the following command in PM Console

    Update-Package -reinstall
    
  2. Open CMD and Create a new SQLLocalDB Instance named LocalDBExample

    SQLLocalDB create LocalDBExample
    
  3. Connect to LocalDBExample Instance with Windows Authentication

    (LocalDB)\LocalDBExample
    
  4. CREATE necessary DATABASE with the following SCRIPT

    CREATE DATABASE ClientDB;
  5. CREATE necessary TABLES with the following SCRIPT (The scripts can be found in the following folder: DB TABLES)

    USE ClientDB;
    
     CREATE TABLE [dbo].[Client] (
         [ID]     INT           IDENTITY (1, 1) NOT NULL,
         [Amount] INT           NULL,
         [Name]   NVARCHAR (50) NULL,
         CONSTRAINT [PK_Client] PRIMARY KEY CLUSTERED ([ID] ASC)
     );

About the application:

In this application, I am going to show how to Encrypted Connection String when you Install your project with Visual Studio Projects and ho to Decrypted Connection String when you start the application on your computer.

Steps

  • Configuration Data Protection Provider.
  • Implement Visual Studio Installer Projects.
  • Configurate Encryption Method in Installer Class.

Useful Highlights:

1. The following code to the App.config.config file of the data protection provider for the connectionString just under

<connectionStrings configProtectionProvider="DataProtectionConfigurationProvider">
  <EncryptedData>
    <CipherData>
      <CipherValue>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAyabPvuLesE+fHSrMeSjz0gQAAAACAAAAAAADZgAAwAAAABAAAAC8JDy9QBfhSRy09ao0c1rOAAAAAASAAACgAAAAEAAAACUs8KSCMHfQZfEaGtmefBMwAAAA/FE3BhMYFaUMhsg2ipmg4RfRq0QArZmU3xazj0ouHCWsvVBLnfBesNrARD9znB9wFAAAAGn3/E4J+zYKFk28lHMBffpBCzKr</CipherValue>
    </CipherData>
  </EncryptedData>
</connectionStrings>

2. The following code to the App.config file of the machine use Data Protection Provider (DPAPI) for the application just under

<configProtectedData>
 <providers>
   <add useMachineProtection="true"
        name="DPAPIProtection"
        type="System.Configuration.DpapiProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
 </providers>
</configProtectedData>

About

C# - WPF - Encyption and Decryption Connection String in Runtime with Visual Studio Installer Projects. [Year of Development: 2018]

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages