Skip to main content
Ortografia.
Fonte Link
Leonel Sanches da Silva
  • 89,6mil
  • 9
  • 125
  • 233

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.

Estou tentando, criptografar minha connectionstring, que esta no meu app.config.

Apos ler alguns foruns, vi que precisa ser criado 2 metodos:

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 blz, metodos 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 esta sem criptografia.

Estou tentando criptografar minha connection string, que está no meu app.config.

Após ler alguns fóruns, vi que precisam ser criados 2 mé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();
        }
    }
}

Até aí beleza, mé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 está sem criptografia.

Fonte Link

Criptografar App.Config

Estou tentando, criptografar minha connectionstring, que esta no meu app.config.

Apos ler alguns foruns, vi que precisa ser criado 2 metodos:

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 blz, metodos 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 esta sem criptografia.