简体   繁体   English

如何从.net中的字符串读取X509签名证书内容?

[英]How to read X509 Signing Certificate content from string in .net?

I have X509 Signing Certificate inside of a string like: 我在像这样的字符串中有X509签名证书:

var signingCertificate = -----BEGIN CERTIFICATE-----\r\nMIICTjCCAbegAw.........-----END CERTIFICATE-----

Now I want to read the content of this certificate. 现在,我想阅读此证书的内容。 i know we can do it using X509Certificate2 object but that reads from file directly. 我知道我们可以使用X509Certificate2对象来做到这一点,但这直接从文件中读取。 Is there anyway to read the content from string? 反正有从字符串中读取内容吗?

You can convert your string to byte array, and create a X509Certificate2 object from it. 您可以将字符串转换为字节数组,并从中创建一个X509Certificate2对象。

byte[] bytes = Encoding.ASCII.GetBytes(signingCertificate);
var x509Certificate2 = new X509Certificate2(bytes);

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

相关问题 具有x509安全证书的ASP.NET Web API - ASP.NET Web API with x509 security certificate 如何找到x509证书的subjectdistinguishedshed名称? - How do I find the subjectdistinguishedname of a x509 certificate? 使用Rsa和x509证书的ProtectedConfigurationProvider - ProtectedConfigurationProvider using Rsa and x509 certificate 如何使用.NET代码中的X509证书进行操作 - How to operate with X509 certificates in .NET code 使用 x509 证书向 Azure AD 验证 Asp.net 4.7.2 应用程序 - Authenticate Asp.net 4.7.2 application to Azure AD using x509 certificate 使用来自Azure Blob的X509证书并在Azure网站中使用它 - Using an X509 certificate from an Azure Blob and using it in an Azure website 从CAC / x509证书扩展中解码ASN.1数据(主题目录属性>公民身份国家/地区) - Decode ASN.1 data from CAC/x509 certificate extension (Subject Directory Attributes > Country of Citizenship) 无法使用X509客户端证书连接到HTTPS - Can't connect to HTTPS using X509 client certificate 为IIS上托管的WCF服务实现自签名X509证书 - Implementing SelfSigned X509 Certificate for WCF Services hosted on IIS 通过asp.net中的X509证书进行客户端身份验证 - Client Authentication via X509 Certificates in asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM