Reputation: 1401
I have searched for an encryption method for storing and retrieving database username and password in web.config, but most of the posts are discussing only about creating a function to encrypt text but not storing as well as retrieving it.
Is there an inbuilt function to encrypt text in C# using a password phrase? I could not find any.
Now I use function given in one of the SO posts for encryption and decryption, but I see some special characters in the encrypted text. If I want to store the encrypted text in web.config the value should be html compliant.
I would be interested in any other approach for both storing and retrieval scenarios.
Upvotes: 2
Views: 779
Reputation: 25370
how about the encrypt/decrypt methods in this example
then
string conn = Decrypt(ConfigurationManager.ConnectionStrings[ConnString].ConnectionString);
Upvotes: 0
Reputation: 12654
You can use Data Protection API to encrypt your data. That data could be decrypted only under current windows user account on this computer.
So, if you create a separate account for you web application pool, only web app would be able to encrypt and decrypt that data.
Upvotes: 1