views:

622

answers:

2

I am using System.Configuration to encrypt and protect some passwords in a custom configuration section vis:-.

static public void SetPassAndProtectSection(string newPassword)
{

    // Get the current configuration file.
    System.Configuration.Configuration config =
        ConfigurationManager.OpenExeConfiguration(
        ConfigurationUserLevel.None);


    // Get the section.
    MyAppProtectedSection section = 
        (MyAppProtectedSection)config.GetSection(DEFAULT_SECTION_NAME);

    section.DBPassword = newPassword;

    // Protect (encrypt)the section.
    section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");

    // Save the encrypted section.
    section.SectionInformation.ForceSave = true;

    config.Save(ConfigurationSaveMode.Full);
}

This appears to work fine but I need some extra information for my documentation.

Where is the Key stored?

How long is the Key?

Michael

+1  A: 

User level keys are stored at

\Documents and Settings{UserName}\Application Data\Microsoft\Crypto\RSA

Machine-level keys at

\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys

Yours is a user-level key.

h0b0
Thanks h0b0 I checked it out and that is correct. I was a little shocked to discover that the machine level keys location has a default access of 'everyone..read'. I'm thinking that I will need to use the user level keys because in my case the user of the key is a windows service that runs as a specific account. Thanks for your response.
Michael Dausmann
A: 

Dear, How can i force the ProtectSection("RsaProtectedConfigurationProvider") to use my own created RSAKeyContainer that i generate by aspnet_regiis.exe tool?

Thanks..

sounds like a 'Dorothy Dix' question to me Samar but.. You need to create a custom configuration provider. this is from my App.config...<configProtectedData defaultProvider="MyCustomRsaProtectedConfigurationProvider"> <providers> <add name="MyCustomRsaProtectedConfigurationProvider"... etcand then use 'MyCustomRsaProtectedConfigurationProvider' in your code instead of 'RsaProtectedConfigurationProvider'
Michael Dausmann