The php Function OpenSSL_Pkey_Get_Private()
Applying signature verification to APIs enables authentication and prevents tampering. This article describes generating a key pair with OpenSSL, creating signature functions with openssl_sign and openssl_verify, and building a simple SDK to simplify usage.
The function openssl_pkey_get_private() allows you to retrieve the private part of an RSA or ECC public/private key. The argument can be a file path (URI) or string containing the key. It works with both PEM and PUF encoded keys. The function returns an array with the key details in success and FALSE if something goes wrong. The key details have indexes bits, key and type (OPENSSL_KEYTYPE_RSA, OPENSSL_KEYTYPE_DSA, OPENSSL_KEYTYPE_DH or OPENSSL_KEYTYPE_EC).
When passing the private data to this function it is recommended that you use a password. If you do not then attackers could read the key from your system and pivot to other systems with this RSA key. The function is used in many applications like Icinga Web 2 to generate a public/private key pair. It is also used to encrypt the monitoring configuration files on the local disk.
The php function openssl_pkey_get_private() is available from PHP version greater than 5.0.0. It can be found in the php source code under src/ext/openssl/.