how to digitally sign a pdf with php (symfony2)?

0

Good morning. My question is how can I digitally sign a pdf file (or what libraries should I use). I am working under the php symfony2 framework. Thank you in advance.

    
asked by devjav 12.08.2016 в 18:52
source

1 answer

1

You have the appropriate extension in PHP itself. You can check the official manual section for more details: link

As an example, I'll make a short and paste of one of the examples I've seen in the manual itself and explain how to sign a file (in this case it's a txt but it could be a pdf or a png or any other ).

<?php
// el mensaje que quiere firmar, por lo que el destinatario puede estar serguro de fue usted
// el que lo envió
$data = <<<EOD

Tiene mi autorización para emplear $10,000 en gastos de comida.

El Presidente
EOD;
// guardar el mensaje en un archivo
$fp = fopen("mensaje.txt", "w");
fwrite($fp, $data);
fclose($fp);
// encriptarlo
if (openssl_pkcs7_sign("mensaje.txt", "firmado.txt", "micert.pem",
    array("file://micert.pem", "mi_frase_de_contraseña"),
    array("Para" => "[email protected]", // sintaxis asociativa
          "DE: C.G. <[email protected]>", // sintaxis indexada
          "Tema" => "Confidencial")
    )) {
    // mensaje firmado - ¡envíelo!
    exec(ini_get("ruta_correo") . " < firmado.txt");
}
?>

When using Symfony you should use the logic inside the Controller that manages the signature of the files.

If you are looking for a bundle that encapsulates this functionality (I do not see much sense) I have found one in packagist, but it does not seem very used or updated: link

    
answered by 16.08.2016 в 13:57