0

I have a private key used to authenticate a REST connection with CURL and OpenSSL, and I want to store the key in a file, so far I wrote the key in the code, and that is a bad idea from security point of view.

I saw PKCS#12 standar and so on, but no code example in C to make my own solution. I need guidance here for the best solution.

jww
  • 97,681
  • 90
  • 411
  • 885
JP Cordova
  • 119
  • 9
  • 1
    See [openssl man page index](https://www.openssl.org/docs/manmaster/man3/) and look at the `PKCS12` and `d2i_` functions, e.g. [d2i_PKCS12](https://www.openssl.org/docs/manmaster/man3/d2i_PKCS12.html). – David C. Rankin Jan 21 '18 at 19:21
  • 2
    The `d2i_` functions go from the *external* representation to the *internal* representation. In other words, they deserialize objects like keys. The `i2d_` functions go the other way, they serialize keys. – President James K. Polk Jan 21 '18 at 20:10
  • 1
    The cited dup should you how to save a key to disk in the four different formats OpenSSL supports. For cURL use `PEM_write_bio_PrivateKey`. It will write both the *info* part and the private key in PEM format. – jww Jan 21 '18 at 22:36
  • That's exactly what I wanted... thank you !!, sorry if I missed the duplicated answers but after search a lot without an answer I avoid any question with 'generate' and 'openssl' in the same sentence... – JP Cordova Jan 22 '18 at 23:45

0 Answers0