views:

1869

answers:

5

I am attempting to encrypt connection string values in the Web.Config file for an ASP.NET 2.0 web application, following the procedure described on MSDN. Using the RsaProtectedConfigurationProvider, I created and exported a machine-level key on my development machine (using the -pri flag), and imported the key and granted access on the web server. Prior to testing automatic decryption by ASP.NET, I wanted to try manually decrypting the Web.Config.

I am able to manually encrypt and decrypt the Web.Config on the same machine using the -pef and -pdf parameters respectively, but manually decrypting on the web server fails with a "Bad Data" error message.

The oddest thing is that the keyContainerName attribute in my Web.Config file seems to be ignored. If I try replacing the correct value with gibberish (no longer corresponding to any key container I have created) the encryption and decryption still work on my development machine. Any ideas?

A: 

Hi,

Actually you can use EL from Microsoft just to encrypt your connection string. You can download it here: http://www.codeplex.com/entlib

hth

KG Sosa
A: 

The RsaProtectedConfigurationProvider uses the machine account or the user account to encrypt the keys and save them in a file which called "key container", which usually saved in C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA. And the ASP.NET worker process identity (ASPNET user in XP/2000 or Network Service in case of 2003) should have access to these files to be able to decrypt it or you would get this error message.

Please check this link for more information

http://msdn.microsoft.com/en-us/library/dtkwfdky.aspx

Sanju
+1  A: 
Sanju
A: 

Be careful that the name of the element to encrypt is case sensitive. So you should use "connectionStrings" not "connectionstrings" or "ConnectionStrings".

mahdi
A: 

Encrpyting is very case sensitive as mahdi said. I have used in my pc and taken it to the sever I had a problem the problem was from the RSA machine key containers that are stored in my PC folder OR directory. and If you want to know where the correction may be started before making any change, Just start from

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

For info, kindly reffer to this link which might be a helpful....

http://msdn.microsoft.com/en-us/library/ms998283.aspx

Ahmed Yassin