简体   繁体   English

从磁盘.Net Core加载X509证书

[英]Load X509 certificate from disk .Net Core

I've created an X509 certificate using OpenSSL. 我使用OpenSSL创建了X509证书。 I am trying to load it using the Import method on the X509Certificate2 class, in .NET Core 2.0. 我试图在.NET Core 2.0中的X509Certificate2类上使用Import方法加载它。

var cert = new X509Certificate2();
cert.Import(_path);

But get thrown the following exception: 但是抛出以下异常:

System.PlatformNotSupportedException : X509Certificate is immutable on this 
platform. Use the equivalent constructor instead.

Which constructor should I be using / what is the correct way to load this certificate from disk? 我应该使用哪种构造函数/从磁盘加载此证书的正确方法是什么?

您可以使用

var x509 = new X509Certificate2(File.ReadAllBytes(_path));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM