How to extract public key from .NET DLL in C #?

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

0
c # rsa cryptoapi
source share
1 answer

To obtain the public key from a signed Autenticode .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 only work if the certificate has been installed in trusted root certification authorities. Otherwise, GetSignerCertificate() returns null.

The second method allows you to obtain a certificate, even if it is not located in trusted root certification authorities.

 X509Certificate executingCert = X509Certificate.CreateFromSignedFile("dll_file_name"); byte[] publicKey = certificate.GetPublicKey(); 
+3
source share

All Articles