pfx文件linux识别不了,.NET 5.0 在 Linux 上读取 pfx 证书的问题

下面的代码在 .net core 3.1 中可以在 linux 上正常读取 pfx 证书,升级到 .net 5.0 之后却无法在 linux 上读取 pfx 证书(在 windows 上没问题)

public static class CertificateFactory

{

public static X509Certificate2 DefaultCertificate

{

get

{

var assembly = typeof(CertificateFactory).GetTypeInfo().Assembly;

using (var stream = assembly.GetManifestResourceStream(

assembly.GetManifestResourceNames().First(r => r.EndsWith("cnblogs.pfx"))))

{

if (stream == null)

throw new ArgumentNullException(nameof(stream));

var bytes = new byte[stream.Length];

stream.Read(bytes, 0, bytes.Length);

return new X509Certificate2(bytes);

}

}

}

}

报错信息如下

289 System.Security.Cryptography.CryptographicException : The certificate data cannot be read with the provided password, the password may be incorrect.

290---- System.Security.Cryptography.CryptographicException : The certificate data cannot be read with the provided password, the password may be incorrect.

291 Stack Trace:

292 at Internal.Cryptography.Pal.UnixPkcs12Reader.Decrypt(SafePasswordHandle password)

293 at Internal.Cryptography.Pal.PkcsFormatReader.TryReadPkcs12(OpenSslPkcs12Reader pfx, SafePasswordHandle password, Boolean single, ICertificatePal& readPal, List`1& readCerts)

294 at Internal.Cryptography.Pal.PkcsFormatReader.TryReadPkcs12(ReadOnlySpan`1 rawData, SafePasswordHandle password, Boolean single, ICertificatePal& readPal, List`1& readCerts, Exception& openSslException)

295 at Internal.Cryptography.Pal.OpenSslX509CertificateReader.FromBlob(ReadOnlySpan`1 rawData, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)

296 at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)

297 at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password)

请问如何解决?

回答

问题补充:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值