【问题标题】:Unable to start Kestrel. Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The specified network password is not correct?无法启动 Kestrel。 Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException:指定的网络密码不正确?
【发布时间】:2020-07-11 13:46:32
【问题描述】:

我创建了一个 Blazor 应用程序,并在创建 C:\Users\wsn2\Test\Certificates\9Cert.pfx 后在 appsettings.json 中添加了以下 json 配置。 (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1)

{
  "Kestrel": {
    "Endpoints": {
      "Https": {
        "Url": "https://*:5005",
        "Certificates": {
          "Path": "C:\\Users\\wsn2\\Test\\Certificates\\9Cert.pfx",
          "Password": "4passWord"
        }
      }
    },
    "Certificates": {
      "Default": {
        "Path": "C:\\Users\\wsn2\\Test\\Certificates\\9Cert.pfx",
        "Password": "4passWord"
      }
    }
  }

但是,运行已发布的自包含 kestrel 应用程序时出现以下错误:

[23:40:25 INF] 用户配置文件可用。使用“C:\Users\wsn2\AppData\Local\ASP.NET\DataProtection-Keys”作为密钥存储库和 Windows DPAPI 来加密静态密钥。 [23:40:25 FTL] 无法启动 Kestrel。 Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException:指定的网络密码不正确。 在 Internal.Cryptography.Pal.CertificatePal.FilterPFXStore(字节 [] rawData,SafePasswordHandle 密码,PfxCertStoreFlags pfxCertStoreFlags) 在 Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(Byte[] rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags) 在 System.Security.Cryptography.X509Certificates.X509Certificate..ctor(字符串文件名,字符串密码,X509KeyStorageFlags keyStorageFlags) 在 System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(字符串文件名,字符串密码) 在 Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.LoadCertificate(CertificateConfig certInfo,字符串端点名称) 在 Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.LoadDefaultCert(ConfigurationReader configReader) 在 Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load() 在 Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.ValidateOptions() 在 Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 应用程序,CancellationToken cancelToken) 未处理的异常。 Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException:指定的网络密码不正确。 在 Internal.Cryptography.Pal.CertificatePal.FilterPFXStore(字节 [] rawData,SafePasswordHandle 密码,PfxCertStoreFlags pfxCertStoreFlags) 在 Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(Byte[] rawData, String fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags) 在 System.Security.Cryptography.X509Certificates.X509Certificate..ctor(字符串文件名,字符串密码,X509KeyStorageFlags keyStorageFlags) 在 System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(字符串文件名,字符串密码) 在 Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.LoadCertificate(CertificateConfig certInfo,字符串端点名称) 在 Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.LoadDefaultCert(ConfigurationReader configReader) 在 Microsoft.AspNetCore.Server.Kestrel.KestrelConfigurationLoader.Load() 在 Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.ValidateOptions() 在 Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer.StartAsync[TContext](IHttpApplication`1 应用程序,CancellationToken cancelToken) 在 Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancelToken) 在 Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancelToken) 在 Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost 主机,CancellationToken 令牌) 在 Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost 主机,CancellationToken 令牌) 在 Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost 主机)

【问题讨论】:

  • 你有解决办法吗?

标签: asp.net-core blazor kestrel-http-server


【解决方案1】:

将您的 9Cert.pfx 文件放在您发布代码的文件夹中

【讨论】:

    【解决方案2】:

    我最终得到了这个:

    • 从这里“http://slproweb.com/products/Win32OpenSSL.html”获取openssl

    • 像这样生成证书(公钥)和私钥:

      openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -keyout web.key -nodes -out web.crt -subj "/C=US/ST=NY/L=Some City/O=MyCompany/ OU=MyCompany/CN=mycompany.com" -addext "subjectAltName=DNS:mycompany.com"

    • 将生成的“web.key”和“web.crt”复制到应用程序文件夹中

    • 将以下部分添加到“appsettings.json”中

       "Kestrel": {
         "Endpoints": {
           "Https": {
             "Url": "https://0.0.0.0:5001"
         }
       },
       "Certificates": {
         "Default": {
           "Path": "web.crt",
           "KeyPath": "web.key"
         }
       }
      

      }

    就是这样。在您的浏览器中尝试“https://localhost:5001/”,系统会提示您有关不受信任的证书,但您仍然可以继续。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-07
      • 2010-10-28
      • 1970-01-01
      • 2022-08-03
      • 1970-01-01
      • 2016-06-12
      • 2022-12-17
      • 2015-09-02
      相关资源
      最近更新 更多