How to extract public key from a .Net DLL in C#? [

2019-09-01 06:10发布

This question already has an answer here:

I want to extract public key, not public key token, in C# from a autenticode signed .Net DLL?

1条回答
冷血范
2楼-- · 2019-09-01 07:00

To get a public key from an Autenticode signed .Net library use the following code:

Assembly assembly = Assembly.LoadFrom("dll_file_name");
X509Certificate certificate = assembly.ManifestModule.GetSignerCertificate();

byte[] publicKey = certificate.GetPublicKey();

But this will work only if the certificate was installed into Trusted Root Certification Authorities. Otherwise, GetSignerCertificate() returns null.

The second way allows to get a certificate even if it isn't in Trusted Root Certification Authorities.

X509Certificate executingCert = X509Certificate.CreateFromSignedFile("dll_file_name");
byte[] publicKey = certificate.GetPublicKey();
查看更多
登录 后发表回答