I'm trying to create an encryption PHP-OPENSSL module to sign data and communicate with a third-party app. I have a digital .PFX certificate (cert.pfx) for this purpose.
I can open it and read it with openssl_pkcs12_read() with my passphrase.
The setup of the third party app ask me to upload the .cer public key of my certificate.
Because, i only have a .pfx file. I'm trying to extract the .cer public key from the PFX to create and upload the .cer file.
I'm using PHP-OPENSSL.
I tried to do it with this command :
$pkeydet = openssl_pkey_get_details(openssl_pkey_get_public(file_get_contents("/path/to/cert.pfx")));
But it doesn't give the expected result (openssl_pkey_get_details() expects parameter 1 to be resource, boolean given). I'm not sure the reason why...
What this the correct way to achieve the creation of the .cer file?
Thank you :)
I think i found the solution, I need to make a conversion from PFX to PEM to CER because the function openssl_pkey_get_details() only works with a .pem certificate.
Here is what I did :
I read the certificate
I write the .CER certificate
I write the .PEM certificate
Now, I can extract the public key from the .PEM :
Because my .CER PK is supposed to be binary, i need to use this function found on php.net to make the conversion :
NOTE: i read that a .cer file can be binary or not
I hope it is correct. I've not yet tested the generated CER but i think i'm maybe close to the solution !
Any comments/advices are welcome :)