0

私はかなり長い間、dev_entlib.config という外部ファイルに保存されているアプリケーション ブロックを暗号化する方法を見つけようとしてきました。

デフォルトの保護プロバイダーを使用してブロックを暗号化できることを entlib (4.1) で確認できますが、このアプリケーションを別のサーバーにデプロイする必要があるため、アプリケーション ブロックの暗号化に使用する keyProvider をそれらのサーバーにエクスポートする必要があります。サーバー。

これまでに行ったことは、任意のフォルダー (およびすべてのターゲット サーバー) の .net v2.0* 内の machine.config ファイルに、カスタムの保護された構成プロバイダーを追加することです。

カスタムプロバイダーはこのようなものです

<add name="MyCompanyProvider" 
    type="System.Configuration.RsaProtectedConfigurationProvider, 
          System.Configuration, Version=2.0.0.0, Culture=neutral, 
          PublicKeyToken=b03f5f7f11d50a3a,
         processorArchitecture=MSIL"
    keyContainerName="MyKey" 
    useMachineContainer="true" />

これは、他の既定のプロバイダーと並んで適切に配置され、Entlib 構成ツールで設計時のサポートさえも備えています。次に、暗号化するブロックごとに保護プロバイダーを選択します。

dev_entlib.config を見ると、実際にブロックがプロバイダーで暗号化されていることがわかります。私のプロバイダーは私のキーコンテナを使用しています。したがって、ブロックはキー コンテナーを使用して暗号化する必要があります。次に、次を使用して「MyKey」をxmlファイルにエクスポートします。

c:\Windows\Microsoft.NET\Framework\v2.0.50727>aspnet_regiis.exe -px "MyKey" "C:\keys.xml" -pri
Exporting RSA Keys to file...
Succeeded!

次に、このキー ファイルが sysTest サーバーにコピーされ、そこでインポートされ、"NT Authority\Network Services" および "ASPNET" へのアクセス権が付与されます。

次に、暗号化された web.config と dev_entlib.config をコピーし、.net ConfigurationManager を使用して ConnectionStrings コレクションを取得してページに表示する小さなページに接続文字列を表示しようとします。このページは IIS で実行されており、プロセスの ID は "NT Authority\Network Services" です。

問題は、それが機能しないことです!不正なデータ エラーまたは「プロバイダー MyCompanyProvider を使用して復号化に失敗しました」があります。

このアプローチは私には理にかなっているように思えますが、それでも失敗します。

誰か別の提案はありますか?

4

2 に答える 2

1

エンタープライズライブラリ構成ツールを使用して、カスタムRSAキーコンテナーで外部エンタープライズライブラリ構成ファイルを暗号化します。

  • EntLib(4.1)は、デフォルトの保護プロバイダーRsaProtectedConfigurationProviderを使用します。ただし、構成ファイル内のこのプロバイダーを削除して、カスタムキープロバイダー「 MyKey 」を指すことができる同じ名前の独自のプロバイダーに置き換えることは可能です。
  • このconfigProtectedDataセクションは、暗号化する領域を含む構成ファイルに追加する必要があります(外部ファイル:* dev_entlib.config *など)。machine.configファイルを変更する必要はまったくありません。
  • 次に、データアクセスアプリケーションブロックProtectionProviderのエンタープライズライブラリ構成アプリケーションからRsaProtectedConfigurationProviderを選択できます。
  • Vista、Windows 7、Windows 2008を使用している場合は、[ 管理者として実行]を使用してこのEntLibConfig.exeを開く必要があります。
    • そうしないと、エラーが発生します。
      • Failed to encrypt the section 'connectionStrings' using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: Object already exists.
  • 次に、この暗号化された*dev_entlib.config*をweb.config構成ファイルと一緒にsysTestサーバーにコピーできます。そのsysTestサーバーでエンタープライズライブラリ構成ツールを使用してweb.configファイルを開くと、エラーが発生し ないはずです。
    • Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: Bad Data.

web.config

このファイルはほとんど空であり、外部データ構成ファイルを指しているだけです。

<!-- web.config -->
<configuration>
  <configSections>
    <section name="enterpriseLibrary.ConfigurationSource" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceSection, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <enterpriseLibrary.ConfigurationSource selectedSource="External Data Configuration File Source">
    <sources>
      <add name="External Data Configuration File Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        filePath="dev_entlib.config" />
    </sources>
  </enterpriseLibrary.ConfigurationSource>
</configuration>

dev_entlib.config

このファイルには、暗号化するための接続文字列と保護プロバイダーが含まれています。

<!-- dev_entlib.config -->
<configuration>
    <configSections>
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
 </configSections>
    <dataConfiguration defaultDatabase="MyConnectionStringName" />
 <connectionStrings>
  <add name="cnHnicMediaLibrary" connectionString="Server=MyDbServer; Database=MyDbName; Integrated Security=SSPI"
   providerName="System.Data.SqlClient" />
 </connectionStrings>
  <configProtectedData>
    <providers>
      <remove name="RsaProtectedConfigurationProvider" />
      <add    name="RsaProtectedConfigurationProvider"
        keyContainerName="MyKey"
        useMachineContainer="true"
        description="Uses our own encryption key container so that it will work in a Web Farm setting. We need to trick Enterprise Library, which wants to use the default RsaCryptoServiceProvider to encrypt and decrypt, by replacing this default provider with our own while this configuration is processed!"
        type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </providers>
  </configProtectedData>
</configuration>

に基づく:

これがあなたが持っていたエラーメッセージとそれを修正する方法を説明していることを願っています。

于 2011-11-09T00:22:58.443 に答える