【发布时间】:2016-02-10 22:39:22
【问题描述】:
我尝试使用下面的代码进行加密,但它只能在我的电脑上使用,其他电脑无法连接到我电脑中的 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);
}
}
}
【问题讨论】:
-
您能否更具体地说明您在寻找什么?您想加密 Web.config 文件。
-
我想加密app.config,我用aspnet_regiis.exe加密后,只有我的PC可以连接到SQL server(在我的PC上),其他PC无法连接。
标签: c# encryption app-config aspnet-regiis.exe