English 中文(简体)
如何加密 Web. config 连接字符串
原标题:How to encrypt web.config connection string

我试图在我的 Web. config 中加密连接字符串 。 我用微软来遵循指南, 但它行不通 。 < a href="http://msdn.microsoft.com/ en- us/library/ff650304. aspx#paght0006_ step3" rel="no follow" >http://msdn.microsoft.com/ en-us/library/ff650304. aspx#paght0006_step3

在我得到“ 加密配置部分成功 ” 命令提示后。 我删除了“ 连接Strings ” 部分 。 配置并保留了新添加的“ 连接Strings ” 和加密数据 。

我有两个用于实体框架的 MSSQL 数据库连接字符串, 但我在运行时间编译时收到一个错误, 说“ < nuger> 指定的连接要么在配置中找不到, 不打算在实体服务器服务器上使用, 要么无效 。

当您打开 edmx 模型文件并从数据库更新模型时。 视觉工作室显示错误, 显示“ 无法使用 RSA Protected Configifation Provider 解密 。... 无法打开 RSA 键盘 。

    <connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
      <EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
        xmlns="http://www.w3.org/2001/04/xmlenc#">
        <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
        <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
          <EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
            <EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
            <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
              <KeyName>Rsa Key</KeyName>
            </KeyInfo>
            <CipherData>
              <CipherValue>..........</CipherValue>
            </CipherData>
          </EncryptedKey>
        </KeyInfo>
        <CipherData>
          <CipherValue>........</CipherValue>
        </CipherData>
      </EncryptedData>
    </connectionStrings>

- - - - - 解决了 回答下面

最佳回答

当您运行 aspnet 命令时, 加密数据应该替换“ 连接Strings ”, 如果它没有, 那么它就失败了 。 aspnet_ regiis -pe “ connectionStrings” - app “/” - 位置“ 子文件夹” - site“ 2 ”

我负责指挥,但结果我不需要 - 地点,这是不正确的。

我早该知道 当密码值XML字段那么小的时候

然而,这两个命令 做这个把戏...

aspnet_regiis -pe " connectionStrings" - app "/" - site "2"

aspnet_regiis -pa "NetFramework ConfigifationKey" - "IIS APPOPOLMYApp" - "NetFramework ConfigifationKey" - "IIS APPOPOLMYApp" - "IIS APPOOLMYApp" - "IAPPOOLMYApp" - "IAPPOOL MyApp" - "InterFramework ConfigationKey" - "IIS App"

问题回答

看起来创建密钥的账户与运行应用程序的账户不同。 您是否确保合适的账户可以访问密钥存储处? 从您发送的文章中...

To grant access to the ASP.NET application identity a.If you are not sure which identity to use, check the identity from a Web page by using the following code:

using System.Security.Principal;

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write(WindowsIdentity.GetCurrent().Name);
}

By default, ASP.NET applications on Windows Server 2003 run using the NT AuthorityNetwork Service account. Open a .NET command prompt, and use the following command to give this account access to the NetFrameworkConfigurationKey store: aspnet_regiis -pa "NetFrameworkConfigurationKey" "NT AuthorityNetwork Service"

If the command runs successfully you will see the following output: Adding ACL for access to the RSA Key container... Succeeded!

您可以在以下文件夹中检查文件的 ACL :

文档和设置 所有用户应用数据

您的 RSA 密钥容器文件是此文件夹中包含最新时间戳的文件 。

此外,

在发布您的工程的服务器上运行此代码

string provider = "RSAProtectedConfigurationProvider";
string section = "connectionStrings";

protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnEncrypt_Click(object sender, EventArgs e)
{
   Configuration confg = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
   ConfigurationSection configSect = confg.GetSection(section);
   if (configSect != null)
   {
      configSect.SectionInformation.ProtectSection(provider);
      confg.Save();
   }
}

protected void btnDecrypt_Click(object sender, EventArgs e)
{
   Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
   ConfigurationSection configSect = config.GetSection(section);
   if (configSect.SectionInformation.IsProtected)
   {
      configSect.SectionInformation.UnprotectSection();
      config.Save();
   }
}

in this link: http://www.codproject.com/Tips/304638/Encrypt-or-Decrypt-Connonction-Strings-in-web-confi

<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>WagJ9DDjWTNc1nmYVNQXaQqXalQzXaiCHAOtUJvTWBRZiuT6UK1fBElM80PnL6dC5Umb8qvfHdkSMgoMW9CJzwOTZ0zTy17JBGZqRQmlfW2G9LacoWIil0UrxjhgmJmRXhwXHFpdGwEVl7AoQGVlJGabXuChutaTxmfGOoUbCr0=</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>qry5qnr3qxOgyoNPeP7OKEiHpr/PPTsaeQ2mYUsSK7cg4Kkl9uPO4RyUXgBIkgCTsjbObqLlyndcSBnYyek6bxG/IBL82G1R5J1ci8i1eyt8kIDqouzYOx5vtouErld4z1L+7WGf9Wg37QAH5RiiEfkCHndJJq3dTqjxnnXZSno6NgbxSXDfqzwE/eKDVhGV3oaTQSfjVmO8e5a9wvREYeeyasDhojx8J2mdy7/Q9rEIpv98RTiRxA==</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>    




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签