Click here to Skip to main content
15,940,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, i have developed an application with c# windowsform.
I need to encrypt my connection string to hide my password (SQL Server as DB).

What I have tried:

I used RSA encrypting method and it works perfectly :
< aspnet_regiis.exe -pef "connectionStrings" "C:\Users\WindowsFormsApplication1" >
and my app.config is updated perfectly.

The problem is when i try to run my app i get this error :
Unable to decrypt using provider 'RsaProtectedConfigurationProvider'. Provider error message: Unable to open RSA key container.
Updated 4-Feb-21 22:27pm

1 solution

It might be that you treat the encrypted data as a string, but we can't tell when you don't provide code. If that's the case, use base64 Format to convert it.

It could also be that the version of aspnet_regiis.exe does not match 32 or 64 bits, or the wrong .NET framework version, see:
ASP.NET IIS Registration Tool (Aspnet_regiis.exe) | Microsoft Docs[^]

Or try the encryption example mentioned here: encryption - Encrypting & Decrypting a String in C# - Stack Overflow[^]
Share this answer
houssem eddine ayari 5-Feb-21 4:40am    
this is my connectionstring before encryption :
<add name="AffecAnalytiqueConnectionString"
="" connectionstring="Data Source=***1;Initial Catalog=***2;Persist Security Info=True;User ID=***3;Password=***4" providername="System.Data.SqlClient">

and this is how i call it in my forms :
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["AffecAnalytiqueConnectionString"].ConnectionString);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900