Skip to content

Convert PFX to PEM or CER

Giancarlos Salas edited this page Feb 16, 2018 · 3 revisions

Convertir Pfx a otros formatos

El archivo resultante se utiliza para firmar los comprobantes electrónicos.

use Greenter\XMLSecLibs\Certificate\X509Certificate;
use Greenter\XMLSecLibs\Certificate\X509ContentType;

require 'vendor/autoload.php';

$pfx = file_get_contents('your-cert.pfx');
$password = 'YOUR-PASSWORD';

$certificate = new X509Certificate($pfx, $password);
$pem = $certificate->export(X509ContentType::PEM);
    
file_put_contents('certificate.pem', $pem);

Convert a .CER

El archivo resultante se utiliza para subirlo a SUNAT.

use Greenter\XMLSecLibs\Certificate\X509Certificate;
use Greenter\XMLSecLibs\Certificate\X509ContentType;

require 'vendor/autoload.php';

$pfx = file_get_contents('your-cert.pfx');
$password = 'YOUR-PASSWORD';

$certificate = new X509Certificate($pfx, $password);
$cer = $certificate->export(X509ContentType::CER);
    
file_put_contents('certificate.cer', $cer);
Clone this wiki locally