Tuesday, November 5, 2013

encrypt and decrypt connectionstring in web config

string connectionString = "data source=123.456.789.00,1234\\abcdb;database=databasename;uid=sa;pwd=123";
            Byte[] a = System.Text.ASCIIEncoding.ASCII.GetBytes(connectionString);
            string encryptedConnectionString = Convert.ToBase64String(a);
         
            Byte[] b = Convert.FromBase64String(ConfigurationSettings.AppSettings["defaultConnection"]);          
            string decryptedConnectionString = System.Text.ASCIIEncoding.ASCII.GetString(b);

http://www.codersource.net/2010/02/03/securing-connection-strings-in-asp-net/