[英]Get Public Key byte array from .cer file - C#
I'm trying to get the public key byte[] from a certificate.我正在尝试从证书中获取公钥字节 []。
My colleague used the command : openssl x509 -inform der -in certificate.cer -text -noout
, which dumped the key on the console and then he copied it into a binary file.我的同事使用了命令: openssl x509 -inform der -in certificate.cer -text -noout
,它将密钥转储到控制台上,然后他将其复制到一个二进制文件中。
My task is to do this using c#
.我的任务是使用c#
来做到这一点。
I used the following lines.我使用了以下几行。
var cert = X509Certificate.CreateFromCertFile(
"C:\\Users\\dhermann\\Downloads\\FirmKeyTest\\FirmwareSubordinateSSLTo20190201PublicKey.cer");
byte[] publicKey = cert.GetPublicKey();
My colleagues bin file has 136 bytes while mine gives me 140 bytes and on top of that, the initial 7 bytes of mine are not included in his byte array, the following 128 are exactly the same as his but the last 8 are different (3 of them not being included in his byte array.我同事的 bin 文件有 136 个字节,而我的给了我 140 个字节,除此之外,我的前 7 个字节没有包含在他的字节数组中,接下来的 128 个与他的完全相同,但最后 8 个不同(3其中没有包含在他的字节数组中。
What am I doing wrong and how can I get the exact same public key array as his?我做错了什么,如何获得与他完全相同的公钥数组?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.