Skip to content

Commit ea0ace3

Browse files
authored
Mejoras en el código de conversión de P12 a PEM
Se ha añadido la detección de errores tanto en la lectura del certificado en formato P12 como en la exportación de la clave privada.
1 parent 89421a1 commit ea0ace3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

docs/wsdlVNif.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,15 @@ Para convertir un certificado P12 o PFX a formato PEM se puede utilizar el sigui
8080
$pkcs12_pass = 'contraseña';
8181
$local_cert = 'certificado.pem';
8282

83-
openssl_pkcs12_read(file_get_contents($pkcs12_file), $certs, $pkcs12_pass);
84-
openssl_pkey_export($certs['pkey'], $pkey, $pkcs12_pass);
85-
file_put_contents($local_cert, $certs['cert'] . $pkey);
83+
if (openssl_pkcs12_read(file_get_contents($pkcs12_file), $certs, $pkcs12_pass)) {
84+
if (openssl_pkey_export($certs['pkey'], $pkey, $pkcs12_pass) or !empty($pkey)) {
85+
file_put_contents($local_cert, $certs['cert'] . $pkey);
86+
} else {
87+
echo 'ERROR: Unable to export private key.', PHP_EOL;
88+
}
89+
} else {
90+
echo 'ERROR: Unable to read the cert store.', PHP_EOL;
91+
}
8692
```
8793

8894
Con el código anterior se convierte el certificado en formato P12 `certificado.pfx` al formato PEM (`certificado.pem`). El nuevo certificado está protegido con la misma contraseña del certificado P12 original.

0 commit comments

Comments
 (0)