Hi All,
I'm trying to convert a .p12 file to a .pem using php (because, as I understand it, soap needs to take a .pem format certificate)
Am I going about it the right way?
$certificate = array();
$pkcs12 = file_get_contents('certificate.p12');
if (openssl_pkcs12_read($pkcs12, $certificate, 'pass')) {
if (isset($certificate['pkey'])) {
$pem = null;
openssl_pkey_export($certificate['pkey'], $pem, 'pass');
}
if (isset($certificate['cert'])) {
$cert = null;
openssl_x509_export($certificate['cert'], $cert);
}
if (isset($certificate['extracerts'][0])) {
$extracert1 = null;
openssl_x509_export($certificate['extracerts'][0], $extracert1);
}
if (isset($certificate['extracerts'][1])) {
$extracert2 = null;
openssl_x509_export($certificate['extracerts'][1], $extracert2);
}
$pem_file_contents = $cert . $pem . $extracert1 . $extracert2;
file_put_contents("certificate.pem", $pem_file_contents);
$options = array(
'local_cert'=>'/absolute/path/to/file/certificate.pem',
'passphrase'=>'pass',
'location'=>"...",
'uri'=>'...',
);