【问题标题】:Error After Encryptingweb.config加密 web.config 后出错
【发布时间】:2010-10-21 18:25:49
【问题描述】:

我加密了我的 web.config 的 AppSettings 部分,在我的机器上对其进行了测试并且它工作,但是当我上传到在线使用它时它给了我一个错误:

配置错误描述:一个 处理过程中发生错误 所需的配置文件 服务这个请求。请查阅 下面的具体错误详细信息和 修改你的配置文件 适当的。

解析器错误消息:未能 使用提供者解密 '数据保护配置提供者'。 来自提供商的错误消息:密钥 在指定状态下使用无效。 (HRESULT 异常:0x8009000B)

Line 24: <appSettings configProtectionProvider="DataProtectionConfigurationProvider">
Line 25:  <EncryptedData>

我使用以下子加密:

Private Sub ProtectSection(ByVal sectionName As String, ByVal provider As String)
        Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)

        Dim section As ConfigurationSection = config.GetSection(sectionName)

        If section IsNot Nothing AndAlso Not section.SectionInformation.IsProtected Then
            section.SectionInformation.ProtectSection(provider)
            config.Save()
        End If
    End Sub

【问题讨论】:

    标签: asp.net vb.net encryption web-config


    【解决方案1】:

    您需要在部分解密后发布。用于加密/解密的密钥是特定于机器的。

    要在线加密配置部分,请调用 global.asax 的 Application_Start() 中的 ProtectSection() 方法。

    【讨论】:

    • 你的意思是我需要在线加密?
    • 是的,您使用的 ProtectSection() 方法将在应用程序第一次受到攻击时执行此操作。
    【解决方案2】:

    您需要设置 MachineKey

    .net 加密使用 MachineKey 作为加密/解密的种子

    http://msdn.microsoft.com/en-us/library/w8h3skw9.aspx

    您需要生成一个密钥并在两台机器上使用它。你也不能只使用自动生成它。

    如果可以的话,更容易在服务器上上传未加密和手动加密,否则你需要完全相同的 MachineKey

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-05
      • 2010-11-07
      • 1970-01-01
      • 2014-10-26
      • 2011-01-31
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      相关资源
      最近更新 更多