$filename = 'apns-dev-cert.p12';
$password = '...';
$results = array();
$worked = openssl_pkcs12_read(file_get_contents($filename), $results, $password));
if($worked) {
echo '<pre>', print_r($results, true), '</pre>';
} else {
echo openssl_error_string();
}
Please try running this snippet. Set $password
to whatever passphrase is needed to open the file. If there's no password, set it to null. I don't believe one is needed from your openssl
commands.
You should get output with the desired private key, probably inside $results['pkey']
.
If you see your private key there, then you can pass it to openssl_pkey_export
to get it in PEM format, which you can then write to a file:
$new_password = null;
$result = null;
$worked = openssl_pkey_export($results['pkey'], $result, $new_password);
if($worked) {
echo "<pre>It worked! Your new pkey is:
", $result, '</pre>';
} else {
echo openssl_error_string();
}
Set $new_password
to your desired pkey password, if you want one.
This should work for you, based on what I'm reading on the various documentation pages.
If you really want to continue using the openssl
command by shelling out, please consider using proc_open
instead of system
, so that you can properly catch error messages.
It's also possible that OpenSSL is trying to read the config file, and doesn't have permission to so, though it should give you an error about that.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…