私はこれに慣れていないので、ご容赦ください。RsaProtectedConfigurationProviderを使用して .config セクションを暗号化/復号化しようとしています
私が間違っている場合は修正してください。しかし、私が読んでいることから、次のことを行う必要があります。
その証明書から証明書と公開鍵を取得する
X509Certificate2 cert = new X509Certificate2(pathToCert, "password"); RSACryptoServiceProvider rsa = cert.PrivateKey as RSACryptoServiceProvider;
この情報をコンテナにロード: 以下のサンプルでは証明書が考慮されていないため、実行方法がわからない
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);
- 次に、App.Config で同じコンテナー名を指定します。
<configProtectedData> <providers> <clear/> <add name="MyProvider" type="System.Configuration.RsaProtectedConfigurationProvider" keyContainerName="MySuperAwesomeKeyContainer" useMachineContainer="true" /> </providers> </configProtectedData>
- 次に、その KeyContainer を使用して暗号化/復号化する次のコードを実行します。
.... string provider = "MyProvider"; // Protect the section. connStrings.SectionInformation.ProtectSection(provider);
これは正しいです?。もしそうなら、どうすればいいですか?? これらのキーを証明書から取得して KeyContainer にロードする方法がわかりません。
ありがとう