0

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'=>'...',
        );
3
Contributors
5
Replies
16
Views
3 Years
Discussion Span
Last Post by gulshanmaurya
0

Well, it generates the file without errors. Not sure if the file content is valid for its purposes though as I'm still having issues connecting to the host via soap.

0

:) no worries. I always appreciate the interest, regardless.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.