Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Strategy to distribute secure database connection strings in an enterprise environment

, 29 Nov 2003
The article discusses a strategy to securely configure and administer a set of connection strings which can be maintained environment wise. It also talks about distributing this information securely in a huge environment to be used by authorized clients only.
ecs_11.zip
enterpriseconnstring_src2003.zip
TestECS
App.ico
UseECS.csproj.user
EnterpriseConnString
EnterpriseConnString.csproj.user
// Copyright � 2003
// Author : Sriram Chitturi
// Date : November 29, 2003

using System;
using Microsoft.Win32;
using System.Configuration;

namespace EnterpriseConnString
{
	// Singleton class to get the keyword
	// from either Registry or config file

	// Customize this class to read KeyWord from any source
	public class Keyword
	{
		private static string m_keyword = null;

		private Keyword()
		{
		}
		public static string GetKeyWord()
		{
			// use any of the methods below to retrieve a keyword, depends on
			// enterprise level security

			if (m_keyword == null)
			{
				// m_keyword = ReadFromRegistry();
				m_keyword = ReadFromConfigFile();
			}
			if (m_keyword.Length != 8)
			{
				m_keyword = null;
				throw new Exception("Keyword should be 8 characters since DES encryption is being used");
			}

			return m_keyword;
		}

		private static string ReadFromRegistry()
		{
			// keyword should be already present in the registry
			// If you want to create keyword in registry
			// use a reg file with the following 3 lines

			// Windows Registry Editor Version 5.00
			// [HKEY_LOCAL_MACHINE\SOFTWARE\ECS]
			// "keyword"="MyKeyWord"

			RegistryKey HKLM = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\ECS");
			string regvalue = (string)HKLM.GetValue("KeyWord");
			if (regvalue == null)
				throw new Exception("KeyWord not found in Registry!");
			return regvalue;
		}

		private static string ReadFromConfigFile()
		{
			// use a config file to set the keyword
			// administrators can use machine.config files to set enterprise wide
			// keywords. This can enable administrators to change keywords often.
			// Note : Whenever the keyword is changed, run admin console to
			//			update the server Registry

			// I am using a local app.config file to set the keyword as an example
			string [] values = ConfigurationSettings.AppSettings.GetValues("keyword");
			if (values == null)
				throw new Exception("Keyword not found in config file!");
			return (string)(values[0]);
		}
	
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Sriram Chitturi
Architect
United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 30 Nov 2003
Article Copyright 2003 by Sriram Chitturi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid