As Remus pointed out, there is user/machine level encryption available.
i'm generally terrified of such things because that data can be lost relativly easily.
If i were you i'd roll my own system. Encrypt the connection strings using a key hard-coded in your application, convert to Base64, and store the resulting, encrypted, connection strings in the registry.
The following function takes a string, encrypts it with AES-256 and the specified key, and base64's the result so it's back as a printable string:
Sample Usage:
String connectionString = EncryptString(
"Provider=SQLOLEDB;Data Source=Mango;User Id=sa;Password=hello",
"A fairly complicated password, like a guid: 8B4B0D73-84C9-4A1E-8DD2-9A189F84FD9B");
public static string EncryptString(string source, string key)
{
Rfc2898DeriveBytes deriveBytes = new Rfc2898DeriveBytes(key, salt);
byte[] derivedKey = deriveBytes.GetBytes(derivedKeySize);
Rijndael rijndael = Rijndael.Create();
rijndael.Mode = cipherMode;
rijndael.Padding = paddingMode;
rijndael.KeySize = keySize;
rijndael.BlockSize = blockSize;
rijndael.FeedbackSize = blockSize; // no bigger than the blocksize
rijndael.Key = derivedKey;
rijndael.IV = iv;
ICryptoTransform transform = rijndael.CreateEncryptor();
byte[] encoded = Encoding.UTF8.GetBytes(source);
byte[] target = transform.TransformFinalBlock(encoded, 0, encoded.Length);
return Convert.ToBase64String(target);
}
public static string DecryptString(string source, string key)
{
Rfc2898DeriveBytes deriveBytes = new Rfc2898DeriveBytes(key, salt);
byte[] derivedKey = deriveBytes.GetBytes(derivedKeySize);
Rijndael rijndael = Rijndael.Create();
rijndael.Mode = cipherMode;
rijndael.Padding = paddingMode;
rijndael.KeySize = keySize;
rijndael.BlockSize = blockSize;
rijndael.FeedbackSize = blockSize; // no bigger than the blocksize
rijndael.Key = derivedKey;
rijndael.IV = iv;
ICryptoTransform transform = rijndael.CreateDecryptor();
byte[] decoded = Convert.FromBase64String(source);
byte[] target = transform.TransformFinalBlock(decoded, 0, decoded.Length);
return Encoding.UTF8.GetString(target);
}
private static readonly byte[] iv = {
0x30,0xA6,0x65,0xDE,0x8C,0x63,0x17,0x44,
0xB6,0xFD,0xEA,0x5F,0x76,0xA1,0x1C,0x5F
};
private static readonly byte[] salt = {
0xF9,0x39,0x0C,0xE0,0x22,0xE0,0x8E,0x84,
0xB2,0x05,0x1E,0xA8,0x6D,0x1C,0x39,0xAC
};
private const int keySize = 256;
private const int blockSize = 128;
private const CipherMode cipherMode = CipherMode.CBC;
private const PaddingMode paddingMode = PaddingMode.PKCS7;
private const int derivedKeySize = 32;