是否可以在web.config文件中的连接字符串中加密用户名和密码(Visual Studio 2015,SQL Server 2014)

Is it possible to encrypt the username and password in the connection string in the web.config file (Visual Studio 2015, SQL Server 2014)

所以我有一个连接字符串标记为:

<connectionStrings>
    <add name="TBL_ClassServices" 
         connectionString="Server=(localdb)\MSSQLLocalDB; database=Assignment1; User Id=test; Password=test"
         providerName="System.data.sqlclient" />
</connectionStrings>

我只想加密用户 ID 和密码,而不加密整个连接字符串本身。是否可能,如果可以,您将如何加密它,然后使用 aspx.cs(C# 后端)代码对其进行解密。

谢谢

我建议使用单独的程序将加密的字符串设置到配置文件中,并在您需要读取连接字符串时在 C# 代码中解密该字符串。这里有一个有用的 post 来完成这个: Encrypt and decrypt a string