首页 文章

解密App.config中的连接字符串

提问于
浏览
2

我有一个控制台应用程序,其中我有一些加密的连接字符串,如下所示:

<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>soemvalue here</CipherValue>
          </CipherData>
        </EncryptedKey>
      </KeyInfo>
      <CipherData>
        <CipherValue>some valye here</CipherValue>
      </CipherData>
    </EncryptedData>
  </connectionStrings>

我尝试使用控制台应用程序访问连接字符串,如下所示:

var connectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;

我收到以下错误:

使用提供程序'RsaProtectedConfigurationProvider'无法解密 . 来自提供程序的错误消息:无法打开RSA密钥容器 .

当我尝试从app.config访问相同的连接字符串而不解密时,它工作正常 . 加密有问题吗?我认为加密后我只需要以正常方式获取连接字符串,它将自动解密 .

1 回答

相关问题