We generally Save the connection string in the following form:
<Deleetask>
<Add key = "ConnectionString" value = "server = localhost; database = test; pwd = sa; uid = sa;"/>
</AppSettings>
Now, a simple encryption is actually base64 encoding instead of encryption.
Private void button#click (object sender, System. EventArgs e)
{
Byte [] data = System. Text. ASCIIEncoding. ASCII. GetBytes (this. TextBox1.Text );
String str = Convert. ToBase64String (data );
This. TextBox2.Text = str;
}
Expected result: Success
Then, we use this string to replace the unencoded string. As follows:
<Deleetask>
<Add key = "ConnectionString" value = "c2VydmVyPWxvY2FsaG9zdDtkYXRhYmFzZT10ZXN0O3B3ZD1zYTt1aWQ9c2E7"/>
</AppSettings>
Our program needs to understand the meaning of this string. we add the following tool methods in the data access layer:
Private string GetConnectionString ()
{
String strconn = System. Configuration. ConfigurationSettings. etettings ["ConnectionString"];
Byte [] data = Convert. FromBase64String (strconn );
String strRealConn = System. Text. ASCIIEncoding. ASCII. GetString (data );
Return strRealConn;
}