c# - How to encrypt app.config? -


create app.config in wpf (c#)

<?xml version="1.0"?> <configuration>   <connectionstrings>     <clear />     <add name="name"      providername="mysql.data"      connectionstring="server=.net;uid=;pwd=h;database=;charset=utf8;allow 0 datetime=true;" />   </connectionstrings> </configuration> 

used code c#:

    configuration config = configurationmanager.openexeconfiguration(configurationuserlevel.none);     connectionstringssection constr = config.connectionstrings;     if (!constr.sectioninformation.isprotected)     {         constr.sectioninformation.protectsection("rsaprotectedconfigurationprovider");         constr.sectioninformation.forcesave = true;         config.save();     }     else     {         foreach (connectionstringsettings ss in constr.connectionstrings)             console.writeline(ss);         console.read();     } 

config.save(); - causes exception:

{"failed encrypt section 'connectionstrings' using provider 'rsaprotectedconfigurationprovider'. error message provider: object exists .\r\n"}

check sectioninformation.protectsection method

also check here


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -