Skip to content
Firma digital de Facturación Electrónica (SUNAT - Perú)
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src fix date key May 29, 2019
tests move manual test to CI May 26, 2019
.gitattributes update ignore files Jan 22, 2018
.gitignore fix tests, exclude files Jan 3, 2018
.travis.yml include composer install May 26, 2019
CHANGELOG.md update to v5 Feb 25, 2018
CONVERT.md update vendor path Feb 16, 2018
LICENSE prep for release Sep 8, 2016
README.md Update descriptions, example Jun 10, 2019
composer.json set require extensions May 26, 2019
phpunit.xml fix phpunit config, remove codacy badge Jan 3, 2018
xmlseclibs.php update xmldsig origin changes May 26, 2019

README.md

XmlDSig - Greenter

Travis-CI Codacy Badge

Esta libreria se emplea para firmar comprobantes electrónicos según las normas de SUNAT.

Se requiere el certificado en formato .PEM, puede utilizar el siguiente ejemplo para convertir el certificado .PFX al otros formatos.

Instalar:

Empleando composer desde packagist.

composer require greenter/xmldsig

Ejemplo


use Greenter\XMLSecLibs\Sunat\SignedXml;

require 'vendor/autoload.php';

$xmlPath = '20600995805-01-F001-1.xml';
$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);

Resultado:

Before:

<ext:UBLExtensions>
    <ext:UBLExtension>
        <ext:ExtensionContent></ext:ExtensionContent>
    </ext:UBLExtension>
</ext:UBLExtensions>

After:

<ext:UBLExtensions>
    <ext:UBLExtension>
        <ext:ExtensionContent>
            <ds:Signature Id="SignIMM">
                <ds:SignedInfo>
                    <ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
                    <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
                    <ds:Reference URI="">
                    <ds:Transforms>
                        <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
                    </ds:Transforms>
                    <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                    <ds:DigestValue>IwJuNQGQaHmmm3iv2jj8JDv70Ow=</ds:DigestValue>
                    </ds:Reference>
                </ds:SignedInfo>
                <ds:SignatureValue>
                nLaghokzMNrmrfPnbIg9b........wzZ2CgLTVjWQUAQ4wDAYDVQQIEwVNYWluZTE1UiLFwZXXXPUlf2o=
                </ds:SignatureValue>
                <ds:KeyInfo>
                    <ds:X509Data>
                        <ds:X509Certificate>
                        MIIFhzCCA3OgAwI......MIIEVDCCAzygAwIBAgIJAPTrkMJbCOr1MA0GCSqGSIb3DQEBBQUAMHkxCzAJBgNVBAYTAlVTVQQIEwVNYWluZTEgMOiRJ00nE=
                        </ds:X509Certificate>
                    </ds:X509Data>
                </ds:KeyInfo>
            </ds:Signature>
        </ext:ExtensionContent>
    </ext:UBLExtension>
</ext:UBLExtensions>
You can’t perform that action at this time.