PEM format https://en.wikipedia.org/wiki/Privacy-Enhanced_Mail
OPENSSL_KEYTYPE_DSA
, OPENSSL_KEYTYPE_DH
, OPENSSL_KEYTYPE_RSA
or OPENSSL_KEYTYPE_EC
<?php
$keyPair = openssl_pkey_new(['private_key_bits' => 512, 'private_key_type' => OPENSSL_KEYTYPE_RSA]);
openssl_pkey_export($keyPair, $privateKey);
$publicKey = openssl_pkey_get_details($keyPair)['key'];