Estou tentando, criptografar minha connectionstringconnection string, que estaestá no meu app.configapp.config
.
AposApós ler alguns forunsfóruns, vi que precisaprecisam ser criadocriados 2 metodosmétodos:
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();
}
}
}
Ate ai blzAté aí beleza, metodosmétodos criados, e depois?
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
{
Mas quando vou olhar o app.config estaapp.config
está sem criptografia.