C# 如何获取非托管exe或dll文件数字签名主题名称?
通常,在C#中,当我们想要获取一些.net文件数字签名主题名称时,我们只需使用:C# 如何获取非托管exe或dll文件数字签名主题名称?,c#,.net,C#,.net,通常,在C#中,当我们想要获取一些.net文件数字签名主题名称时,我们只需使用: string Subject = AsseblyObject.GetModules().First().GetSignerCertificate().Subject; 但是我想要非托管的exe或dll文件数字签名主题名称。 还有别的办法吗?谢谢。这是我在数字签名存档文件上使用的内容(即,这些文件根本不受管理): 这是一个精简版,让您开始使用-我还内置了很多检查和异常抛出功能,有很多东西需要注意。@slugster
string Subject = AsseblyObject.GetModules().First().GetSignerCertificate().Subject;
但是我想要非托管的exe或dll文件数字签名主题名称。
还有别的办法吗?谢谢。这是我在数字签名存档文件上使用的内容(即,这些文件根本不受管理):
这是一个精简版,让您开始使用-我还内置了很多检查和异常抛出功能,有很多东西需要注意。@slugster,谢谢。我测试它。这很好。也谢谢你让我知道更多。
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
var signer = X509Certificate.CreateFromSignedFile("[path to the file]");
var cert = new X509Certificate2(signer);
var certChain = new X509Chain();
certChain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot;
certChain.ChainPolicy.RevocationMode = CheckRevocOffline ? X509RevocationMode.Offline : X509RevocationMode.Online;
certChain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 0, 0);
certChain.ChainPolicy.VerificationFlags = VerificationFlags;
var certChainIsValid = certChain.Build(cert);
if (!certChainIsValid)
{
//file is likely to be self signed, revoked or expired
}
var subjectName = cert.SubjectName.Name;