2009-04-25 3 views
4

後、私は、私のweb.configファイルののAppSettings一部を暗号化し、私のマシン上でそれをテストし、それが働いたが、私はそれをオンラインで使用するためにアップロードされたとき、それは私にエラーました:エラーEncryptingweb.config

Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Failed to decrypt using provider 'DataProtectionConfigurationProvider'. Error message from the provider: Key not valid for use in specified state. (Exception from HRESULT: 0x8009000B)

Line 24: <appSettings configProtectionProvider="DataProtectionConfigurationProvider"> 
Line 25: <EncryptedData> 

私は、暗号化するために、以下のサブを使用:

Private Sub ProtectSection(ByVal sectionName As String, ByVal provider As String) 
     Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath) 

     Dim section As ConfigurationSection = config.GetSection(sectionName) 

     If section IsNot Nothing AndAlso Not section.SectionInformation.IsProtected Then 
      section.SectionInformation.ProtectSection(provider) 
      config.Save() 
     End If 
    End Sub 

答えて

3

あなたは、復号化のセクションで公開する必要があります。暗号化/復号化に使用される鍵は、マシン固有です。

オンラインで設定セクションを暗号化するには、global.asaxのApplication_Start()でProtectSection()メソッドを呼び出します。

+1

まったく同じのmachineKey必要ですか? – Maen

+1

はい、使用しているProtectSection()メソッドは、アプリケーションが最初にヒットしたときにこれを行います。 – Jeremy

+1

それは問題を解決しましたか...ありがとうございます... – Maen

1

あなたが

.NETの暗号化は、暗号化/復号化キーを生成し、両方のマシン上でそれを使用する必要が

http://msdn.microsoft.com/en-us/library/w8h3skw9.aspx

のシードとしてのmachineKeyを使用するのmachineKeyを設定する必要があります。あなたはそれを自動生成することもできません。

だけで暗号化されていないをアップロードし、あなたができる場合は、サーバー上で手動で暗号化することが容易に、そうでなければ、あなたは、私はそれをオンラインで暗号化する必要があるわけ

関連する問題