WPF開発ノウハウ集

ログを暗号化/複合化する

ログを暗号化する

log4net暗号化ライブラリの用意

ArtisanCode.Log4NetMessageEncryptor.dll
ArtisanCode.SimpleAesEncryption.dll

dllの参照をプロジェクトに追加

App.config の追加設定

  <?xml version="1.0" encoding="utf-8"?>
  <configuration>
      
      <configSections>
        <section name="Log4NetMessageEncryption" type="ArtisanCode.Log4NetMessageEncryptor.Log4NetMessageEncryptorConfiguration, ArtisanCode.Log4NetMessageEncryptor"/>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
      </configSections>
      
      <startup> 
          <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/>
      </startup>

      <Log4NetMessageEncryption CipherMode="CBC" Padding="ISO10126">
        <EncryptionKey KeySize="256" Key="3q2+796tvu/erb7v3q2+796tvu/erb7v3q2+796tvu8="/>
      </Log4NetMessageEncryption>

  </configuration>

log4net.config を書き換える

暗号化キーを隠蔽する

標準では暗号化キーを App.config に平文で記述しているため、これを隠蔽するために 暗号化を行う ArtisanCode.SimpleAesEncryption.dll を改変する


暗号化されたログファイルの複合化

ArtisanCode.Log4NetMessageEncryptor のソースコードに同梱されているツールを使用する

  LogDecrypt.exe