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から同じ接続文字列にアクセスしようとすると、正常に機能します。暗号化に問題はありますか?暗号化後、通常の方法で接続文字列をフェッチするだけで、自動的に復号化されると思いました。

4

1 に答える 1

4

同じマシンで暗号化と復号化を行うか、キーをエクスポート/インポートする必要があります。

この記事を参照してください:

http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/d43a4bd7-7cc1-40cf-8269-82c92894df43/

于 2012-09-28T16:51:32.623 に答える