none
What is best secured way to store connection string in app.config RRS feed

  • Question

  • i have stored my connection string in config file after encryption. when user open my config then they will not be able to understand but if any developer try to know the actual connection string then they can do it. if they debug the code then they can see what algo and salt i used to encrypt & decrypt connection string. so please discuss any best way by which no one will be able to see what is actual connection string ?

    how could i secured connection string which i will know only or i can decrypt only after encrypt but from same dev team other one will not be able to read it back or decrypt. so please discuss few good ways. thanks

    Friday, February 14, 2020 3:14 PM

All replies

  • Essentially, what you are trying to do is impossible. If the program is to be able to use the connection string, then the program has to contain everything that is necessary for decrypting the connection string, otherwise it would not be capable of using it. Therefore, a sufficiently knowledgeable programmer will always be able to find the value from the connection string by following the execution of the program.

    The remedy is to not store the secrets in the connection string (alone), but rather require something that is stored outside the program. You could store the key for decoding the connection string, o even the whole connection string, in Windows using the Data Protection API. Or you could use integrated authentication, so that there are no secrets in the connection string; instead the user that logged-in into Windows is passed to the database. Or you could ask the user to enter the password instead of saving it in the connection string.

    Note that none of the preceding methods will stop the legitimate user who is allowed to run the program from finding out the connection string. They only serve to protect it from illegitimate users who are not allowed to use the application. If you need to protect the database from the user, assign a different login to each allowed user, and then tweak the permissions in the database to only allow each user to access the parts that are permitted for such user.

    Friday, February 14, 2020 8:36 PM
    Moderator
  • Thinking along the same lines as Alberto, seems creating a login for users with appropriate permissions would be the way to go.

    Check out my Microsoft TechNet article SQL Server database login for Windows Forms (C#) with source code on GitHub in this repository.

    Then the authorized users use a login eg.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, February 14, 2020 10:57 PM
    Moderator