Encrypt password in App.config

后端 未结 4 881
渐次进展
渐次进展 2020-11-27 04:21

I want to encrypt the password in connection string. When I make a connection to DB the connection string is openly stored in App.config and I need to find a way to keep onl

4条回答
  •  不知归路
    2020-11-27 04:37

    Lets say this is your connection string:

    
        
    
    

    Then you can do something like this:

    string myCs = System.Configuration.ConfigurationManager.ConnectionStrings["cs"].ConnectionString;
    
    System.Data.SqlClient.SqlConnectionStringBuilder csb = new System.Data.SqlClient.SqlConnectionStringBuilder(myCs);
    csb.Password = EncDecHelper.Decrypt(csb.Password);
    myCs = csb.ToString();
    

    You can write EncDecHelper.Decrypt by using samples from here: Encrypt and decrypt a string

提交回复
热议问题