Web lists-archives.com

Export private key in PKCS#8 format using openssl bindings?


I wonder, what's the best way to export a private key from a keypair
generated with `openssl_pkey_new()` into PKCS#8 format in PHP.

I use the PHP openssl bindings to generate and export a private/public

> $pKey = openssl_pkey_new();
> openssl_pkey_export($pKey, $privateKey);
> $publicKey = openssl_pkey_get_details($pKey)['key'];

Unfortunately, for some reason, PHP openssl bindings still export the
private key in traditional format, instead of using the PKCS#8 format.

Since the openssl bindings don't seem to support exporting in PKCS#8
format, it seems like I have two options:

1. spawn a system process and use `openssl pkey` to transform the
   exported key into PKCS#8 format.
2. add phpseclib dependency and use it to import+export the generated
   key in PKCS#8 format.

Do you have other ideas? Am I missing something?

Looking forward to your responses.


Attachment: signature.asc
Description: OpenPGP digital signature