Created
January 21, 2013 13:13
-
-
Save brankoajzele/4585931 to your computer and use it in GitHub Desktop.
Converting .cer to .pem via pure PHP, (no system, backticks, shell_exec, exec, etc.) to get the same result as with "openssl x509 -inform der -in cert.cer -out cert.pem". Note, I am not expert on certificates, etc. This specific certificate conversion simply worked for me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$certificateCAcer = '/certificate.cer'; | |
$certificateCAcerContent = file_get_contents($certificateCAcer); | |
/* Convert .cer to .pem, cURL uses .pem */ | |
$certificateCApemContent = '-----BEGIN CERTIFICATE-----'.PHP_EOL | |
.chunk_split(base64_encode($certificateCAcerContent), 64, PHP_EOL) | |
.'-----END CERTIFICATE-----'.PHP_EOL; | |
$certificateCApem = $certificateCAcer.'.pem'; | |
file_put_contents($certificateCApem, $certificateCApemContent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for your code, is really useful.