0

hope you can help me. i'm using X509Certificate2 and X509Store to write a certificate (.pfx) into X509Store. Then i go to the dns and request the publicKey token from it, once it reply i see the publicKey i get is in Base64 wheres when i find the proper X509Certificate2 from the X509Store i cant find any way to represent publicKey to match the one i get from the dns.

how can i get the base64 representation of the public key to look like dns?!

I have already tried to use: byte[] arrBytes = certificate2.GetPublicKey(); and byte[] arrBytes = certificate2.PublicKey.EncodedKeyValue.RawData

both are not giving me the same base64 as the one i get from dns, or am i missing some thing?!

Thanks for the help :)

Biryukov Pavel
  • 397
  • 4
  • 18

1 Answers1

0

Found an answer in this two threads:

C# Export Private/Public RSA key from RSACryptoServiceProvider to PEM string

and

C# RSA Public Key Output Not Correct

Take ExportPublicKey function from second link and use:

 string st1 = ExportPublicKey((RSACryptoServiceProvider)certificate2.PublicKey.Key);

where certificate2 is X509Certificate2 object from your X509Store . Got that working for me! :)

Community
  • 1
  • 1
Biryukov Pavel
  • 397
  • 4
  • 18