Last post Aug 26, 2013 06:06 PM by musakkhir
Jul 21, 2012 06:14 AM|Ophelia|LINK
I am trying to encrypt my connection string which contains the username and the password for my database in my hosting. I read a few articles online and i followed them but i am constantly getting this error:
Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: Bad Data.
Maybe there's something else that i should do before i copy my web.config to my hosting?
Does anyone have a step by step guide?
Jul 21, 2012 06:30 AM|Basquiat|LINK
This worked for me...
(you are encrypting after publishing..right?)
Jul 21, 2012 06:58 AM|Ophelia|LINK
I want to encrypt in locally and then i want to copy it to my hosting account... The link that you are refering to does the job with a button click. I want it to do it automatically..
Jul 21, 2012 07:08 AM|Basquiat|LINK
How will you decrypt it if it was locally encrypted?
Jul 21, 2012 07:22 AM|Ophelia|LINK
Ok i am missing something.. Why do i nee to decrypt it? the web app cannot "recognise" the encrypted one? I have to do it manually with a button click. e.g with an administrator account?
Jul 21, 2012 09:42 AM|Basquiat|LINK
This is my basic understanding of it:
You can encrypt it from the DOS prompt, if you have access to it..
c:\windows\microsoft.net\framework\Vx\aspnet_regiis.exe -pef "connectionStrings" c:\Inetpub\foldername
...and you only have to do this once.
The key to decrypt it lies on the same machine where it was encrypted.
When your application access the connectionstrings it would automatically do the decryption.
If it was encrypted on a local and then published, the webserver would not be able to decrypt it, so you have to encrypt it on the webserver.
Because of that, and because you will probably continue working on your website and re-publish, replacing the encrypted webconfig with a new not-encrypted one.....it is convenient to have an admin panel with a button from where you can encrypt
Jul 21, 2012 10:28 AM|Ophelia|LINK
Ok i think i understand it now..
i used this: aspnet_regiis.exe -pef "connectionStrings" c:\Inetpub\foldername
so i have to do it with the way you suggest it in order to run in the web server. Can i use a button to run code of the class and then delete the button and just keep a backup of the web.config file in my pc? Sorry if i sound stupid but this is the
first time that i am trying this and english is not my native language..
Jul 21, 2012 10:53 AM|Damn Code|LINK
Try to write this in code-behind
protected void Encryption(bool EncryptoValue)
Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
ConfigurationSection sec = config.GetSection("connectionStrings");
if (EncryptoValue == true)
protected void Button1_Click(object sender, EventArgs e)
protected void Button2_Click(object sender, EventArgs e)
Jul 21, 2012 11:44 AM|Basquiat|LINK
Jul 22, 2012 11:38 AM|Ophelia|LINK
I am getting this error on both ways that you suggested. The 2nd way i think that its from an asp.net/learn/videos. I think that i found it when i was searching.
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration
Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Any ideas? :P
Jul 22, 2012 01:26 PM|Basquiat|LINK
Jul 22, 2012 03:15 PM|Ophelia|LINK
No i did not.. I tried it directly on my host because i was pretty sure that the code was ok because i saw it on a video here... I think that it has to do with the trustlevel or something like that... I am searching about it right now..
Jul 23, 2012 03:38 AM|Ophelia|LINK
So after talking at the support forum of the godady they told me:
"Windows hosting within our shared environment is configured to work in “Medium Only” Trust Levels. If your script is attempting functions that require “Full” trust permissions it will not function. You also cannot alter these permissions through a web.config.
If you require ‘Full Trust’ permissions, you will need setup your ASP Runtime to 1.1 as ‘Full Trust’ is enabled under the settings. Otherwise, your script would need to be configured to use “Medium Only” Trust."
What a disappointment. I have to either go back to 1.1 or leave my connectrion string unencrypted. Maybe there's some other way of doing this?
Jul 23, 2012 05:34 AM|Basquiat|LINK
I had a feeling that would be the case, I don't know of another way...but would be very interested if there is.
I would suggest a new post "Encrypt web.config on shared host"?
Jul 23, 2012 06:37 AM|Ophelia|LINK
Yes i think i should. thank you. :)
Aug 26, 2013 04:23 AM|zeroxs|LINK
Hi.. may this will help you ? http://cafalse.blogspot.com/2013/07/skyse-alternative-database-connection.html
Aug 26, 2013 06:06 PM|musakkhir|LINK