0

Without using Bouncy Castle - using just C# .NET I need to generate a public/private key pair and send the public key to a service by BASE64 Encoding the key in DER format.

Can anyone help with the export in DER format? I can create the keypair easily enough but the DER format has me stumped.

user2709214
  • 185
  • 2
  • 12
  • Why do you not want to use Bouncy Castle? – Hooman Bahreini Jul 14 '18 at 00:33
  • So, you have the public key already generated, and need to convert it to DER format? What format is it currently, PEM? – Russ Cam Jul 14 '18 at 00:48
  • 4
    .NET doesn't provide a DER or ASN.1 encoder in the BCL so you have two options: start reading reference docs (http://luca.ntop.org/Teaching/Appunti/asn1.html) and write your own, or use a 3p library such as Bouncy Castle or Open SSL etc. – Mike Dinescu Jul 14 '18 at 01:01
  • By the way, this answer shows the format of an ASN.1 public key: https://stackoverflow.com/questions/1281102/reading-a-asn-1-der-encoded-rsa-public-key/5266564#5266564 you would be generating this – Mike Dinescu Jul 14 '18 at 01:03
  • https://stackoverflow.com/a/48039170/6535399 may help. If you don't have a certificate you can perhaps use https://stackoverflow.com/a/47099047/6535399 to figure out how to build the RSAPublicKey value for WrapAsBitString – bartonjs Jul 16 '18 at 16:28

1 Answers1

0

You could also use OpenSSL

If your server/device requires a different certificate format other than Base64 encoded X.509, a third party tool such as OpenSSL can be used to convert the certificates into the appropriate format.

GitHub - OpenSSl.NET

Hooman Bahreini
  • 14,480
  • 11
  • 70
  • 137