在Ubuntu中读取pfx证书以创建X509



我正在Ubuntu中运行一个.NET Core应用程序,并尝试连接到具有以下功能的云RavenDB实例:

var bytes = File.ReadAllBytes("/etc/ssl/certs/foo.pfx");
var clientCert = new X509Certificate2(bytes, "foo");
var store = new DocumentStore
{
Urls = new[] { "https://a.free.foo.ravendb.cloud" },
Certificate = clientCert,
Database = "FooDatabase"
};
store.Initialize();
builder.Services.AddSingleton<IDocumentStore>(store);

当应用程序启动时,我收到以下错误:

System.Security.Cryptography.CryptographicException:ASN1损坏的数据。--->System.Formats.Asn1.AsnContentException:编码的长度超过了此库支持的最大值(Int32.MaxValue(。在System.Formats.Asn1.AsnCoder.ReadLength(ReadOnlySpa1 source, AsnEncodingRules ruleSet, Int32& bytesConsumed) at System.Formats.Asn1.AsnDecoder.ReadEncodedValue(ReadOnlySpan1源,AsEncodingRules规则集,Int32&contentOffset,Int32&contentLength,Int32&bytesConsumed(位于Internal.Cryptography.Pal.UnixPkcs12Reader.ParsePkcs12(ReadOnlyPan`1数据(

我需要以某种方式将pfx文件加载/安装到服务器上吗?

我的问题似乎是我的pfx文件以某种方式损坏了。可能是由于我试图将其复制到服务器的方式。在重新上传我的pfx文件后,我可以使用以下内容:

var clientCert = new X509Certificate2("/etc/ssl/certs/foo.pfx");

您不需要呼叫ReadAllBytes

最新更新