相关疑难解决方法(0)

无法将密钥文件添加到 X509Certificate2

环境:VS 2019、Core 3.1、C# 8.0

我在尝试将 .cer 和 .key 文件添加到我的 httpClientHandler 时收到以下错误:

    {"ASN1 corrupted data."}
        Data: {System.Collections.ListDictionaryInternal}
        HResult: -2146233087
        HelpLink: null
        InnerException: null
        Message: "ASN1 corrupted data."
        Source: "System.Security.Cryptography.Algorithms"
        StackTrace: "   at System.Security.Cryptography.Asn1.AsnReader.CheckExpectedTag(Asn1Tag tag, Asn1Tag expectedTag, UniversalTagNumber tagNumber)\r\n   at System.Security.Cryptography.Asn1.AsnReader.ReadSequence(Asn1Tag expectedTag)\r\n   at System.Security.Cryptography.Asn1.RSAPrivateKeyAsn.Decode(AsnReader reader, Asn1Tag expectedTag, RSAPrivateKeyAsn& decoded)\r\n   at System.Security.Cryptography.Asn1.RSAPrivateKeyAsn.Decode(Asn1Tag expectedTag, ReadOnlyMemory`1 encoded, AsnEncodingRules ruleSet)\r\n   at System.Security.Cryptography.Asn1.RSAPrivateKeyAsn.Decode(ReadOnlyMemory`1 encoded, AsnEncodingRules ruleSet)\r\n   at System.Security.Cryptography.RSAKeyFormatHelper.FromPkcs1PrivateKey(ReadOnlyMemory`1 keyData, AlgorithmIdentifierAsn& algId, RSAParameters& ret)\r\n   at System.Security.Cryptography.RSA.ImportRSAPrivateKey(ReadOnlySpan`1 source, Int32& bytesRead)\r\n   at BnyMellon.Program.CreateFromCertFile(String cerFile, String keyFile) in C:\\Users\\bbernzweig.AD\\source\\repos\\HttpClientExample\\
    BnyMellon\\Program.cs:line 150" …
Run Code Online (Sandbox Code Playgroud)

.net c# httpclient x509certificate2 .net-core

5
推荐指数
1
解决办法
4979
查看次数

不使用BouncyCastle的C#中的数字签名

不使用第三方BouncyCastle库,是否可以读取自定义私钥并对消息签名?(使用私钥进行sha256哈希+加密)

c# rsa signature sha256 digital

3
推荐指数
2
解决办法
1795
查看次数

标签 统计

c# ×2

.net ×1

.net-core ×1

digital ×1

httpclient ×1

rsa ×1

sha256 ×1

signature ×1

x509certificate2 ×1