I use the function openssl_pkey_get_details
to get the details of my keys (primes, exponents...).
Key types I managed are mostly RSA and EC ones.
Example:
<?php
$pemFilename = 'file://'.__DIR__ . '/public.es256.key';
$keyResource = openssl_pkey_get_public($pemFilename);
$details = openssl_pkey_get_details($keyResource);
With the code above, the data contained in the $details
is an array with the components of my key.
Now I would like to convert back this array into a key resource i.e. the inverse function of the one above.
Example:
$keyResource = function_to_be_defined($details);
Is there any way to do it without external libraries?
The comments recommend to use function openssl_pkey_get_private
, but it accepts only the file path to a PEM key or a string that contains the key in PEM format.