0

私はこれに慣れていないので、ご容赦ください。RsaProtectedConfigurationProviderを使用して .config セクションを暗号化/復号化しようとしています

私が間違っている場合は修正してください。しかし、私が読んでいることから、次のことを行う必要があります。

  1. その証明書から証明書と公開鍵を取得する

    X509Certificate2 cert = new X509Certificate2(pathToCert, "password");
    RSACryptoServiceProvider rsa = cert.PrivateKey as RSACryptoServiceProvider;
    
  2. この情報をコンテナにロード: 以下のサンプルでは証明書が考慮されていないため、実行方法がわからない

http://msdn.microsoft.com/en-us/library/tswxhw92(en-us,VS.80).aspx

    // Create the CspParameters object and set the key container 
    // name used to store the RSA key pair.
    CspParameters cp = new CspParameters();
    cp.KeyContainerName = "MySuperAwesomeKeyContainer";

    // Create a new instance of RSACryptoServiceProvider that accesses
    // the key container MyKeyContainerName.
    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(cp);
  1. 次に、App.Config で同じコンテナー名を指定します。
<configProtectedData>
<providers>
 <clear/>
  <add name="MyProvider"
  type="System.Configuration.RsaProtectedConfigurationProvider"
  keyContainerName="MySuperAwesomeKeyContainer"
  useMachineContainer="true" />
</providers>
</configProtectedData>
  1. 次に、その KeyContainer を使用して暗号化/復号化する次のコードを実行します。
....
string provider = "MyProvider";
// Protect the section.
connStrings.SectionInformation.ProtectSection(provider);

これは正しいです?。もしそうなら、どうすればいいですか?? これらのキーを証明書から取得して KeyContainer にロードする方法がわかりません。

ありがとう

4

2 に答える 2

0

手順は、チュートリアル: RSA キー コンテナーの作成とエクスポート にあります。証明書は必要ありません。キー コンテナーを直接生成できます。

カスタム構成セクションを暗号化する場合、それを機能させるための秘訣があります: configSection の宣言を削除する必要があります。ここで詳細をブログに書きました: ASP.NET でカスタム構成セクションを暗号化する方法

于 2013-06-12T21:14:21.707 に答える