GenerateEmailConfirmationTokenAsync(user)生成错误加密失败

时间:2017-06-22 19:09:48

标签: asp.net-core

GenerateEmailConfirmationTokenAsync(user)方法的调用将返回错误消息Encryption Failed

这是一个带有资源服务器和身份验证服务器的.Net核心应用程序。用户帐户管理正在资源服务器上完成。当执行到达

 var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

我收到错误消息Encryption Failed

以下是数据保护的配置

var cert = new X509Certificate2(Path.Combine(folderForKeyStore, "teejay.pfx"), "xxxxxxxxxx");
var folderForKeyStore = Configuration["Data:KeyStoreFolderWhichIsBacked:keystore"];
services.AddDataProtection()
           .SetApplicationName("Academic Records Management System")
          .ProtectKeysWithDpapiNG("CERTIFICATE=Hashid:" + cert.Thumbprint, flags: DpapiNGProtectionDescriptorFlags.None)
            .PersistKeysToFileSystem(new DirectoryInfo(folderForKeyStore));

以下是堆栈跟踪

at     Microsoft.AspNetCore.Cryptography.UnsafeNativeMethods.ThrowExceptionForNCryptStat    usImpl(Int32 ntstatus)       at     Microsoft.AspNetCore.DataProtection.Cng.DpapiSecretSerializerHelper.ProtectWithDpapiNGCore(NCryptDescriptorHandle protectionDescriptorHandle, Byte* pbData, UInt32 cbData)
   at     Microsoft.AspNetCore.DataProtection.Cng.DpapiSecretSerializerHelper.ProtectWithDpapiNG(ISecret secret, NCryptDescriptorHandle protectionDescriptorHandle)

at Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiNGXmlEncryptor.Encrypt(XElement plaintextElement)    在Microsoft.AspNetCore.DataProtection.XmlEncryption.XmlEncryptionExtensions.EncryptIfNecessary(IXmlEncryptor encryptor,XElement element)    在Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.IInternalXmlKeyManager.CreateNewKey(Guid keyId,DateTimeOffset creationDate,DateTimeOffset activationDate,DateTimeOffset expirationDate)    在Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.CreateNewKey(DateTimeOffset activationDate,DateTimeOffset expirationDate)    在Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.CreateCacheableKeyRingCore(现在是DateTimeOffset,IKey keyJustAdded)    在Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.ICacheableKeyRingProvider.GetCacheableKeyRing(DateTimeOffset now)    在Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRingCore(DateTime utcNow)    在Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte [] plaintext)    在Microsoft.AspNetCore.Identity.DataProtectorTokenProvider 1.<GenerateAsync>d__11.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()    在E:\ Projects \ School \ ARMS \ ARMS.ResourceServer \ Controllers \ UserManagerController.cs中的ARMS.ResourceServer.Controllers.UserManagerController.d__25.MoveNext():第271行 ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__27.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__25.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&amp; next,Scope&amp; scope,Object&amp; state,Boolean&amp; isCompleted)    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__22.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State&amp; next,Scope&amp; scope,Object&amp; state,Boolean&amp; isCompleted)    在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__20.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.d__7.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束---    在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)    在Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.d__6.MoveNext()

因此,在阅读了一段时间后,我设法深入了解事件查看器,这就是我找到的

enter image description here

有一件事是显而易见的。我的自签名Certifiates肯定存在问题,但不明显的是如何处理这个问题。有人帮帮我!!

0 个答案:

没有答案