How do I create a DLL file to encrypt the connection string ?

Shahab a 261 Reputation points
2022-10-12T15:16:47.78+00:00

Hi all
I have a connection string to connect to the database.

For Example:

Data Source=.;Initial Catalog=MyDatabase;Integrated Security=True

In Visual Studio, when the build software is created in the debug folder of the XML file, the connection string can be seen in the name of the same project in the file and in the connection string tag.
Or I can encrypt the connection string in the app.config file.

This is an idea that I want to store this connection string in a DLL file as encryption and call it in my project.
Or in any other way that professional teachers consider.
Please, considering that I am a beginner, give a suitable example along with the code sample.
Please, the sample codes should be in VB.NET language.
Thanks All

Developer technologies | VB
{count} votes

Accepted answer
  1. Sreeju Nair 12,666 Reputation points
    2022-10-12T16:57:24.363+00:00
    1 person found this answer helpful.

5 additional answers

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2022-10-12T18:26:53.073+00:00

    The solution you are proposing to store the string in a DLL encrypted solves no security problems. It is wasted effort. You could store the connection string in your app and accomplish the same thing. But none of this really matters because you can easily extract encrypted strings from binaries just as easily as you can from the config file (which is where they normally reside). So you're just adding work that makes you think it is safer when it actually doesn't do anything.

    If you must store sensitive data in your config file then encrypt the connection string as @Sreeju Nair mentioned. But bear in mind that anybody with a debugger can still get the unencrypted string.

    If your app is deployed on a server and you are concerned about the server being compromised then store the sensitive data somewhere else such as in Key Vault or another third party "password" management system. Then have your app call that. But be aware that if you put calls directly into your app then anybody with access to it can do the same thing.

    If you just want to keep sensitive data out of your source control then consider storing the data in Key Vault (or similar) or in environment variables on the server (or somewhere on the server more secure).

    If your app is a client app then there is no place to store this data securely. In most cases it is better to have it call an API that then talks to the secure backend to get the data needed (e.g. a database). For per-user data you could store it in their per-user directory structure so others wouldn't have access (except admins) but it depends on what you're storing.

    1 person found this answer helpful.
    0 comments No comments

  2. Shahab a 261 Reputation points
    2022-10-13T18:25:44.327+00:00

    Hi @Michael Taylor

    Thank you very much for your professional explanations.
    My program is installed on the server and actually the connection string is the only connection with the software.
    And I'm worried about compromising the data on the server.

    If it is possible for you, please provide a sample code for this algorithm so that I can use it.


  3. Shahab a 261 Reputation points
    2022-10-14T08:15:07.937+00:00

    Hi @Sreeju Nair
    In this link
    52301.vb-net-secure-connection-string-for-windows-forms.aspx
    And in the title Securing connection strings row one

    Copy said project ConfigurationLibrary_vb

    Where is this project?

    Please help Me.


  4. Shahab a 261 Reputation points
    2022-11-02T14:03:26.657+00:00

    Hi @Sreeju Nair

    I created a new project and added the two projects you see in the picture
    256416-1.jpg

    But I put this line of code in form 1

        Private operations As New ConnectionProtection(True, Application.ExecutablePath)  
    

    256423-22.jpg

    and see the following error

    Severity	Code	Description	Project	File	Line	Suppression State  
    Error	BC30002	Type 'ConnectionProtection' is not defined.	  
    

    How to solve this error?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.