public static string Decode(string connectionString, string keyName) { if (connectionString == "") { return(""); } SqlConnectionStringBuilder connBuilder = new SqlConnectionStringBuilder(connectionString); string regKeyName = string.Format("Password_{0}", keyName); if (!connBuilder.IntegratedSecurity) { byte[] protectedPassword = RegistryHandler.ReadByte(regKeyName); if (protectedPassword != null) { string unprotectedPassword = Encoding.UTF8.GetString(ProtectedData.Unprotect(protectedPassword, null, DataProtectionScope.CurrentUser)); string clearTextPassword = AesDecrypt(unprotectedPassword, _cipherKey); connBuilder.Password = clearTextPassword; } } return(connBuilder.ToString()); }