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.
My task is to do this using 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.
What am I doing wrong and how can I get the exact same public key array as his?