Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取非托管exe或dll文件数字签名主题名称?_C#_.net - Fatal编程技术网

C# 如何获取非托管exe或dll文件数字签名主题名称?

C# 如何获取非托管exe或dll文件数字签名主题名称?,c#,.net,C#,.net,通常,在C#中,当我们想要获取一些.net文件数字签名主题名称时,我们只需使用: string Subject = AsseblyObject.GetModules().First().GetSignerCertificate().Subject; 但是我想要非托管的exe或dll文件数字签名主题名称。 还有别的办法吗?谢谢。这是我在数字签名存档文件上使用的内容(即,这些文件根本不受管理): 这是一个精简版,让您开始使用-我还内置了很多检查和异常抛出功能,有很多东西需要注意。@slugster

通常,在C#中,当我们想要获取一些.net文件数字签名主题名称时,我们只需使用:

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;