PHP code example of greenterose / xmldsig

1. Go to this page and download the library: Download greenterose/xmldsig library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

greenterose / xmldsig example snippets



use Greenter\XMLSecLibs\Sunat\SignedXml;

certPath = 'certifcate.pem'; // Convertir pfx to pem (public+private key) 

$signer = new SignedXml();
$signer->setCertificateFromFile($certPath);

$xmlSigned = $signer->signFromFile($xmlPath);

file_put_contents("signed.xml", $xmlSigned);