簡體   English   中英

機器密鑰設置為SHA1時無法驗證數據錯誤

[英]Unable to validate data error with machine key set to SHA1

我在IIS 7.5中使用.NET 2.0運行時有一個簡單的.net應用程序,我在web.config中更改了機器密鑰以使用以下內容:

  <machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps" validation="SHA1"/>

這在本地工作正常,但當我發布到服務器時,我得到一個“HttpException(0x80004005):無法驗證數據”每當瀏覽網站時。 我已確保設置編譯debug =“false”。 將驗證方法設置為3DES可以消除此問題,但我們需要使用SHA1。 我在這里缺少一些配置選項嗎? 看下面的堆棧跟蹤。

 [HttpException (0x80004005): Unable to validate data.] System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo, Boolean signData) +1008 System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo) +91 System.Web.UI.Page.EncryptStringWithIV(String s, IVType ivType) +83 System.Web.UI.Page.EncryptString(String s) +30 System.Web.Handlers.RuntimeScriptResourceHandler.GetScriptResourceUrlImpl(List`1 assemblyResourceLists, Boolean zip, Boolean notifyScriptLoaded) +1497 System.Web.Handlers.RuntimeScriptResourceHandler.System.Web.Handlers.IScriptResourceHandler.GetScriptResourceUrl(List`1 assemblyResourceLists, Boolean zip, Boolean notifyScriptLoaded) +1148 System.Web.Handlers.RuntimeScriptResourceHandler.System.Web.Handlers.IScriptResourceHandler.GetScriptResourceUrl(Assembly assembly, String resourceName, CultureInfo culture, Boolean zip, Boolean notifyScriptLoaded) +152 System.Web.Handlers.ScriptResourceHandler.GetScriptResourceUrl(Assembly assembly, String resourceName, CultureInfo culture, Boolean zip, Boolean notifyScriptLoaded) +37 System.Web.UI.ScriptManager.GetScriptResourceUrl(String resourceName, Assembly assembly) +105 System.Web.UI.ScriptRegistrationManager.RegisterClientScriptResource(Control control, Type type, String resourceName) +113 System.Web.UI.ScriptManager.System.Web.UI.IScriptManager.RegisterClientScriptResource(Control control, Type type, String resourceName) +14 System.Web.UI.ClientScriptManager.RegisterClientScriptResource(Control control, Type type, String resourceName) +53 System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e, Boolean registerScript) +113 System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e) +25 System.Web.UI.Control.PreRenderRecursiveInternal() +80 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Control.PreRenderRecursiveInternal() +171 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842 

您是否在真正的.NET 2.0應用程序池中運行該應用程序? (我問,因為你使用的是IIS 7.5)。

如果沒有,請記住.NET 4.5框架中的加密算法已發生變化。

如果您需要與<.NET 4.5 Framework兼容,則需要兼容性標記:

<machineKey compatibilityMode="Framework20SP1" />  

請參閱http://msdn.microsoft.com/en-us/library/system.web.configuration.machinekeysection.compatibilitymode.aspxhttp://blogs.msdn.com/b/webdev/archive/2012/10/23 /cryptographic-improvements-in-asp-net-4-5-pt-2.aspx了解詳情。

我發現當“系統密碼學:使用fips兼容算法進行加密,散列和簽名”(安全設置>>本地策略>> securityOptions)的本地安全策略設置為true時,Sha1將無法正常工作,這就是原因為什么我在這種情況下得到錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM