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
Post a Comment