从磁盘.Net Core加载X509证书

时间:2017-12-11 15:45:45

标签: c# ssl https .net-core x509certificate

我使用OpenSSL创建了X509证书。我正在尝试使用.NET Core 2.0中的X509Certificate2类上的Import方法加载它。

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

但是抛出以下异常:

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

我应该使用哪种构造函数/从磁盘加载此证书的正确方法是什么?

1 个答案:

答案 0 :(得分:16)

您可以使用

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