配置 .pfx 证书

Configure .pfx certificate

我正在使用 .Net 5.0,当我将其发送到托管服务器时出现这些错误。一段时间后,由于这些错误,我的网站出现 HTTP 错误 500。我使用 OpenSSL 创建了证书,用户配置文件为 true,但是当我尝试添加证书时出现这些错误。

我该怎么办?

  warn: Microsoft.AspNetCore.DataProtection.Repositories.EphemeralXmlRepository[50]
          Using an in-memory repository. Keys will not be persisted to storage.
    warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[59]
          Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.
    warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
          No XML encryptor configured. Key {f071590d-e902-4b6f-bbbe-d27d7415d96b} may be persisted to storage in unencrypted form.
    crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
          Application startup exception
          Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The system cannot find the file specified.
        

我的启动是这样的:

services.AddDataProtection()
            .SetApplicationName("MyProjectName")
            .ProtectKeysWithCertificate(new X509Certificate2(certificate, "password", X509KeyStorageFlags.MachineKeySet
                             | X509KeyStorageFlags.PersistKeySet
                             | X509KeyStorageFlags.Exportable))  //My bad line of code
                   .UseCryptographicAlgorithms(
                    new AuthenticatedEncryptorConfiguration()
                    {
                        EncryptionAlgorithm = EncryptionAlgorithm.AES_256_CBC,
                        ValidationAlgorithm = ValidationAlgorithm.HMACSHA256
                    }
             )
             .PersistKeysToFileSystem(new DirectoryInfo(keysFolder)) //shared network folder for key location
             .SetDefaultKeyLifetime(TimeSpan.FromDays(600));

问题是服务器端的问题已过时。提供商更新服务器,问题已解决