如何使用 C# 获取 X509Certificate2 对象的签名?

How can I get the signature of an X509Certificate2 object using C#?

我需要使用 C# 从证书中获取签名和用于创建该签名的算法。

我能做到吗?如果是,如何?

你将不得不求助于充气城堡,

https://github.com/bcgit/bc-csharp/blob/master/crypto/src/x509/X509Certificate.cs#L240

它的 X509Certificate class 使您可以访问此 属性。

我现在正在开发具有类似功能的应用程序。而且我真的很失望为什么微软没有添加 属性 签名到 X509Certificate2 class

我知道如何通过 bouncycastle 做到这一点

从那里开始http://www.bouncycastle.org/csharp/

然后添加代码

using System;
using System.Security.Cryptography.X509Certificates;
using bcrypto = Org.BouncyCastle.X509;

.

var cert = new X509Certificate2("c:\temp\0c50000343119659.cer");
var certParser = new bcrypto.X509CertificateParser();
var privateCertBouncy = certParser.ReadCertificate(cert.GetRawCertData());
var xx = privateCertBouncy.GetSignature();
Array.Reverse(xx);
//Signature
Console.WriteLine(BitConverter.ToString(xx));
//algorithm
Console.WriteLine(privateCertBouncy.SigAlgName);
Console.ReadLine();