ASP.NET - รหัสผ่านเครือข่ายที่ระบุไม่ถูกต้อง

ฉันมีไคลเอ็นต์ WCF ในเครื่อง dev ซึ่งต้องใช้ใบรับรองและทำงานได้ดี
หลังจากการปรับใช้กับเซิร์ฟเวอร์ที่ใช้งานจริง ฉันได้รับข้อผิดพลาดต่อไปนี้:

[CryptographicException: The specified network password is not correct.]

DEV - Win7 32BIT IIS 7.5
การผลิต - Win SERVER 64BIT 2008 IIS 7.5

แม้ว่าจะไม่มีรหัสผ่านระหว่างเครือข่ายและไม่มีรหัสผ่านใบรับรองก็ตาม (ฉันรู้เพราะ dev ทำงานโดยไม่มีรหัสผ่าน) รหัสผ่านเดียวที่ฉันมีคือ WCF ที่เหมือนกับ DEV

CrmServiceClient crm = new CrmServiceClient("CrmServiceEndpoint");
crm.ClientCredentials.UserName.UserName = CrmConfigRepository.CrmUserName;//fine
crm.ClientCredentials.UserName.Password = CrmConfigRepository.CrmPassword;//fine
crm.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(Path);
///THIS WONT WORK AS WELL
crm.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(Path, "", X509KeyStorageFlags.Exportable); 

นี่คือสแต็คเต็ม

[CryptographicException: The specified network password is not correct. ]
   System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +41
   System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromFile(String fileName, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) +0
   System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags) +372
   System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName) +101
   Externals.CrmConnection.Get() in C:\Users\avi\Documents\Visual Studio 2010\Projects\ExpressBroker\Externals\CrmConnection.cs:31
   ExpressBroker.Models.ActionsMetadata.Handlers.LeadAccountHandler.Handle(BrokerAction brokerAction, ActionStep step, Dictionary`2 httpPostDataCollection) in C:\Users\avi\Documents\Visual Studio 2010\Projects\ExpressBroker\ExpressBroker\Models\ActionsMetadata\Handlers\LeadAccountHandler.cs:45
   ExpressBroker.Models.ActionsMetadata.Handlers.BaseStepHandler.SecuredHandle(BrokerAction brokerAction, ActionStep step, Dictionary`2 httpPostDataCollection) in C:\Users\avi\Documents\Visual Studio 2010\Projects\ExpressBroker\ExpressBroker\Models\ActionsMetadata\Handlers\BaseStepHandler.cs:49
   ExpressBroker.Models.ActionsMetadata.Handlers.HandlerInvoker.Invoke(BrokerAction brokerAction, ActionStep actionStep, Dictionary`2 stepValues) in C:\Users\avi\Documents\Visual Studio 2010\Projects\ExpressBroker\ExpressBroker\Models\ActionsMetadata\Handlers\StepServerInoker.cs:29
   ExpressBroker.Controllers.LeadAccountController.Register(String step) in C:\Users\avi\Documents\Visual Studio 2010\Projects\ExpressBroker\ExpressBroker\Controllers\LeadAccountController.cs:28
   lambda_method(Closure , ControllerBase , Object[] ) +127
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +264
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +129
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +784922
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +314
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +784976
   System.Web.Mvc.Controller.ExecuteCore() +159
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371

ขอบคุณ


person SexyMF    schedule 27.11.2011    source แหล่งที่มา
comment
เส้นทางที่ส่งผ่านในตัวสร้างใบรับรอง X509 คืออะไร ฉันคิดว่ามันเป็นรหัสผ่านเครือข่ายในการเข้าถึงไฟล์ใบรับรอง   -  person Simon    schedule 27.11.2011
comment
ซ้ำกันได้ไหม? stackoverflow.com/q/899991/130352   -  person Chris J    schedule 29.01.2015


คำตอบ (3)


ลองสิ่งนี้:

new X509Certificate2(Path, "", X509KeyStorageFlags.MachineKeySet); 

ดูเหมือนว่าตัวสร้าง X509Certificate2 พยายามเข้าถึงที่เก็บคีย์ส่วนตัวของผู้ใช้ในเครื่อง (แม้ว่าในขณะที่โหลด PFX และคีย์ส่วนตัวอยู่ใน PFX) เมื่อใช้ asp.net โดยทั่วไปโปรไฟล์ผู้ใช้จะไม่โหลด ดังนั้นจึงไม่มีที่เก็บคีย์ผู้ใช้ การระบุ MachineKeySet จะบอก Constructor ให้ดูที่ที่เก็บคีย์ของ Local Computer ซึ่งมีอยู่เสมอ

person fatnjazzy    schedule 28.11.2011
comment
หากคุณตั้งค่าพารามิเตอร์ X509KeyStorageFlags มันจะสร้างไฟล์คีย์ในโฟลเดอร์ C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys ทุกครั้งที่คุณสร้างอินสแตนซ์อ็อบเจ็กต์ X509Certificate2 หากคุณทำสิ่งนี้บ่อยครั้งคุณอาจทำให้ดิสก์เต็ม ดังนั้นใช้ นี้อย่างระมัดระวัง - person NahuelGQ; 31.03.2016
comment
ทางออกที่ดีที่สุดสำหรับฉันคือการทำให้ asp โหลดโปรไฟล์ผู้ใช้ ตรวจสอบ stackoverflow.com/a/10048789/356604 - person NahuelGQ; 31.03.2016
comment
มันทำงานได้อย่างสมบูรณ์แบบ หากคุณมีรหัสผ่านและต้องการใช้ คุณจะต้องเรียกใช้ด้วยวิธีนี้ X509Certificate2 Certificate = new X509Certificate2(Path, yourpassword, X509KeyStorageFlags.MachineKeySet); - person Victor.Uduak; 17.05.2018
comment
แค่อยากพูดถึง X509Certificate2 ใหม่ (เส้นทาง, รหัสผ่านของคุณ, X509KeyStorageFlags.MachineKeySet); - person Mohammad Hassani; 02.02.2020

ฉันยังมีปัญหากับไฟล์ pfx ปัญหาคือมันถูกส่งออกโดยใช้การเข้ารหัส AES256-SHA256 ซึ่งมีข้อยกเว้นเดียวกันกับในคำถาม ตามสิ่งนี้ AES256-SHA256 รองรับบน Windows 10 1703 เท่านั้น , Windows Server 2016 ขึ้นไป การเปลี่ยนเป็น TripleDES-SHA1 'แก้ไข' ปัญหา

person ferikeem    schedule 17.03.2021
comment
ดูเพิ่มเติม: ลิงก์ - person ferikeem; 17.03.2021
comment
หากมีบุคคลอื่นประสบปัญหานี้โดยพยายามโหลดใบรับรองที่เข้ารหัส AES256 บนพอร์ทัล Azure หรือโหลดด้วยโค้ดจากอาร์เรย์ไฟล์/ไบต์... ฉันได้รับข้อผิดพลาดเดียวกัน (ทำให้เข้าใจผิด) ซึ่งฉันแก้ไขได้เฉพาะการส่งออกใหม่เท่านั้น ใบรับรองใน 3DES-SHA1 ซึ่งแปลกเพราะในพื้นที่ใช้งานได้ แต่หยุดทำงานเมื่อเผยแพร่บนเว็บแอป... PS: ก่อนหน้านั้น ฉันลองย่อรหัสผ่านให้สั้นลงด้วย แต่ก็ไม่ได้แก้ปัญหาอะไรเลย - person Luke; 03.05.2021

ฉันมีปัญหานี้กับไฟล์ใบรับรอง PFX ที่มีชุดรหัสผ่าน 40 ตัวอักษร Windows อนุญาตให้ฉันส่งออกและนำเข้าได้ แต่ไม่สามารถใช้ในรหัส C# ได้ ดังนั้นฉันจึงเปลี่ยนเป็นรหัสผ่าน 30 ตัวอักษรและมัน ทำงาน

person Peroxy    schedule 07.07.2020