5
I’m trying to encrypt my Connection string, that’s in my app.config
.
After reading some forums, I saw that 2 methods need to be created:
class proteger_app
{
public static void Criptografar()
{
Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSection section =
config.ConnectionStrings;
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider");
section.SectionInformation.ForceSave = true;
config.Save();
}
}
public static void Decriptografar()
{
Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConnectionStringsSection section =
config.ConnectionStrings;
if (section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
section.SectionInformation.ForceSave = true;
config.Save();
}
}
}
Until then beauty, methods created, and then?
public void chek()
{
string sqconn, _sql;
int th;
proteger_app.Decriptografar();
sqconn = ConfigurationManager.ConnectionStrings["sql brayton"].ConnectionString;
proteger_app.Criptografar();
_sql = @"SELECT id FROM base64";
SqlConnection con = new SqlConnection(sqconn);
try
{
But when will I look at the app.config
is unencrypted.
It doesn’t make much sense. Why do you want to encrypt inside the application? The correct is outside, per command line.
– Leonel Sanches da Silva
Haaaaaa... could you give me an explanation? or some link that directs me to some documentation? would you have to create within my application, a console? and when I execute ?
– Thomas Erich Pimentel