如何从 C# 中的 .Net DLL 中提取公钥? [英] How to extract public key from a .Net DLL in C#?

查看:48
本文介绍了如何从 C# 中的 .Net DLL 中提取公钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 C# 中从 autenticode 签名的 .Net DLL 中提取公钥,而不是公钥令牌?

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

推荐答案

要从经过 Authenticode 签名的 .Net 库获取公钥,请使用以下代码:

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

但这只有在证书安装到受信任的根证书颁发机构时才有效.否则,GetSignerCertificate() 返回 null.

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

这篇关于如何从 C# 中的 .Net DLL 中提取公钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆