WinFormへのApp.configファイルを暗号化する
3943 ワード
最近WinFormのプロジェクトをしていますが、クライアントで直接データベースに接続する方式を採用しているため、クライアントにAppを配備する必要があります.configは、Enterprise Libraryを使用しているため、Appが必要です.configファイルのconnectionStringsの断片を暗号化処理し、MSDNを検索すると、すでに既存のツールASPがあることが判明した.NET IIS登録ツール(Aspnet_regiis.exe)は、ASPのみに対応する.NETのWeb.configファイル、まさか私たちは仕方がありませんか?答えはもちろん否定的だ.構成オプション
-pdf section webApplicationDirectory
指定物理(非仮想)ディレクトリのWeb.configファイルの指定した構成セクションを復号します.
-pef section webApplicationDirectory
指定物理(非仮想)ディレクトリのWeb.configファイルの指定した構成セクションを暗号化します.
-pdfおよび-pefパラメータは、指定する物理ディレクトリのWebである.configファイルを暗号化するには、まずAppを使用します.configファイルをWebと改名configは、この2つのパラメータでシステムを「騙す」ことができ、指定した構成セクションを暗号化することができ、暗号化されたファイル名をAppに戻すだけです.configでいいです.最初のステップ:まずディレクトリの下のAppを試してみましょう.configはWebと改名した.config.ステップ2:SDKコマンドプロンプトを開き、コマンドを入力:aspnet_regiis-pef「構成セクション」「ディレクトリ」、私のプロジェクトを例にとると、暗号化前のconfigファイルの内容は以下の通りです.
入力コマンド:aspnet_regiis-pef「connectionsStrings」「E:開発ディレクトリ」、暗号化されたconfigファイルの内容は以下の通りです.
このように、私たちはすでに任務を完成しました.今はWebをconfigファイル名をAppに変更します.configでよい、アプリケーション項目においてそのファイルを復号操作する必要はない.NETフレームワークは自動的に作成されます.このファイルを解読するのも簡単です.SDKコマンドプロンプトにaspnet_を入力します.regiis-pdf「構成セクション」「ディレクトリ」でいいです.
-pdf section webApplicationDirectory
指定物理(非仮想)ディレクトリのWeb.configファイルの指定した構成セクションを復号します.
-pef section webApplicationDirectory
指定物理(非仮想)ディレクトリのWeb.configファイルの指定した構成セクションを暗号化します.
-pdfおよび-pefパラメータは、指定する物理ディレクトリのWebである.configファイルを暗号化するには、まずAppを使用します.configファイルをWebと改名configは、この2つのパラメータでシステムを「騙す」ことができ、指定した構成セクションを暗号化することができ、暗号化されたファイル名をAppに戻すだけです.configでいいです.最初のステップ:まずディレクトリの下のAppを試してみましょう.configはWebと改名した.config.ステップ2:SDKコマンドプロンプトを開き、コマンドを入力:aspnet_regiis-pef「構成セクション」「ディレクトリ」、私のプロジェクトを例にとると、暗号化前のconfigファイルの内容は以下の通りです.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<dataConfiguration defaultDatabase="Connection String" />
<connectionStrings>
<add name="Connection String" connectionString="Database=LocomotiveStat;Server=10.167.61.49;User ID=sa;Password=sa;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
入力コマンド:aspnet_regiis-pef「connectionsStrings」「E:開発ディレクトリ」、暗号化されたconfigファイルの内容は以下の通りです.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<dataConfiguration defaultDatabase="Connection String" />
<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>g2QFQqbHU1L6WUPYqjADqFAvHcdq/7dqCd1U9GlQFEi/nHDVHjqsWvjNywOZtQQg7Q/yW7g8xlRCo0h2+yYd/tQTNoVMu/RKdJmSjZMnmnwpWq+S2VEWK4U106JQwLCfBR/bAF4DHvG47B9KB0JbRfXBt5V2wJVaAI9u3kzuj50=</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>blwV/ZW1izFZL80YL5RkcjrIjWkQ0L1gJhgZbxEzzTgOcT24ihrAnv3/rDCG+WIZ7TL5D/rMm7dQwkIsij1Sh3befg6F3+pxcW4oe1w/bovIKuzjs3tokUpBvTTj+fsCs2W/MWUhQaWMKQWkHfS2Ajt6gL6MTYtb3pfQUp0pdHbeRxoqdiAksQ1Zzsi1FtRTi7gTT7hnpF0pJs+W9mxTVDMO/qSZXfXLOEMIs/A5ExcfvR5GjpaPuDeLuSsCN3XtjaiXzaDQ3It7j+r66+L2C0xvEhbT9SsG</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
</configuration>
このように、私たちはすでに任務を完成しました.今はWebをconfigファイル名をAppに変更します.configでよい、アプリケーション項目においてそのファイルを復号操作する必要はない.NETフレームワークは自動的に作成されます.このファイルを解読するのも簡単です.SDKコマンドプロンプトにaspnet_を入力します.regiis-pdf「構成セクション」「ディレクトリ」でいいです.