加密ConnectionStrings App.config

时间:2015-11-10 05:24:33

标签: c# encryption app-config aspnet-regiis.exe

我尝试使用下面的代码加密,但它只能在我的PC上使用,其他PC无法连接到我的PC中的SQL服务器。有人帮我吗?非常感谢!!! (我也尝试使用aspnet_regiis.exe但遇到同样的问题)

        public static void ProtectSection(String sSectionName)
    {
        Configuration config = ConfigurationManager.OpenExeConfiguration("TFLManager.exe");

        // Get the section in the file.
        ConnectionStringsSection section = config.GetSection(sSectionName) as ConnectionStringsSection;
        // If the section exists and the section is not readonly, then protect the section.
        if (section != null)
        {
            if (!section.IsReadOnly())
            {
                // Protect the section.
                section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
                section.SectionInformation.ForceSave = true;
                // Save the change.
                config.Save(ConfigurationSaveMode.Modified);
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

在所需的计算机上以管理员身份启动命令提示符。 在命令提示符下,输入:

 cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

如果您的Web Config位于“D:\ Code \ EncryptWebConfig”目录路径中,请输入以下内容以加密ConnectionString:

ASPNET_REGIIS -pef "connectionStrings" "D:\Code\EncryptWebConfig"
相关问题