I have a code that makes the transformation but need to do it with native PHP functions because it is not activated support for running exec:
exec("openssl pkcs8 -inform DER -in 'archivo.key' -out 'archivo.key.pem' -passin pass:'lacontrasena'");
Someone can help me translate this into native PHP functions? It can be openssl
or a library.
//Updated
This is my code using der2pem function:
function der2pem($der_data) {
$pem = chunk_split(base64_encode($der_data), 64, "\n");
$pem = "-----BEGIN PRIVATE KEY-----\n".$pem."-----END PRIVATE KEY-----\n";
return $pem;
}
$keyfile = 'myFileDER.key';
$keyFileContent = file_get_contents($keyfile);
$pemContent = der2pem($keyFileContent);
file_put_contents('llavetemp.pem', $pemContent);
$private_key1 = openssl_pkey_get_private($pemContent);
var_dump($private_key1);
The var_dump return boolean false
You can easily use uri2x's answer and a few informations from the first google result. PEM is just the base64-encoded form of the binary DER file. Some Metadata is added and you can do everything with it.
so if you modify the function (posted by uri2x!) to the following:
you can now call it:
and you can transform nearly everything which needs to bee transferred in crypto-concerns:
...and many others!
See dan's comment on
php.net
: