views:

182

answers:

1

In my applications we.config file I have a connection string stored. I encrypted it using

  '---open the web.config file
    Dim config As Configuration = _
       ConfigurationManager.OpenWebConfiguration( _
       Request.ApplicationPath)
    '---indicate the section to protect
    Dim section As ConfigurationSection = _
       config.Sections("connectionStrings")
    '---specify the protection provider
    section.SectionInformation.ProtectSection(protectionProvider)
    '---Apple the protection and update
    config.Save()

Now I can decrypt it using the code

   Dim config As Configuration = _
       ConfigurationManager.OpenWebConfiguration( _
       Request.ApplicationPath)
    Dim section As ConfigurationSection = _
       config.Sections("connectionStrings")
    section.SectionInformation.UnProtectSection()
    config.Save()

I want to know where is the key stored.
Also If somehow my web.config file is stolen, will it be possible for him/her to decrypt it using thhe code above.

+1  A: 

The user keys are stored in:

[Letter]:\Documents and Settings\[User]\Application Data\Microsoft\Crypto\RSA

Machine keys are in:

[Letter]:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys

If someone has the file and the keys then yes, they'll be able to decrypt. If only the file, no they won't be able to.

Also, if they decrypt using the same code on the same server, then yes. However, if they reach your server, it's all over anyways.


EDIT to add into the answer from comments:

  • Q: If I copy the key and paste it in some other PC along with the web.config, will it be decrypted?
  • A: If i'm not mistaken, the key will only work on that machine unless you do an import/export. However, as I say, if someone has gained access do this, you will be "dead in the water" already, as the compromised server will be devastating.

  • Q: I created one more web application and encrypted it.I see that no new key is created there.Did it use the same key for the 2nd application?

  • A: As far as I know, yes. The keys are generated per machine, per user to my knowledge.
Kyle Rozendo
Kyle, If I copy the key (the fodler in \CRYPTO\RSA) and paste it in some other PC along with the web.config, will it be decrypted ?
Akshay
If i'm not mistaken, the key will only work on that machine unless you do an import/export. However, as I say, if someone has gained access do this, you will be "dead in the water" already, as the compromised server will be devastating.
Kyle Rozendo
Please let me ask one more question, what I did was, delete the contents of the folder Crypto\RSA and then encrypt the web.config.But nothing is added to that folder. I was expecting a key to be generated there.What must have happened ?
Akshay
Which folder did you check? The first or second?
Kyle Rozendo
"C:\Documents and Settings\NEWUSER\Application Data\Microsoft\Crypto\RSA"-This folder is empty. But I see it created in "C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys".....My mistake I didnt see the "All Users" folder.It's getting created there. :)
Akshay
One more thing.I created one more web application and encrypted it.I see that no new key is created there.Did it use the same key for the 2nd application ?
Akshay
As far as I know, yes. The keys are generated per machine, per user to my knowledge.
Kyle Rozendo
I came to know that we have 2 options.First-Machine key which is for all users and User Level Key which is the key for individual users.Thanks Kyle !
Akshay