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

荒凉一梦 提交于 2019-12-08 13:44:46

问题


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


回答1:


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();


来源:https://stackoverflow.com/questions/28832048/how-to-extract-public-key-from-a-net-dll-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!