PHPackages                             asystec/firmador - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. asystec/firmador

ActiveLibrary[Security](/categories/security)

asystec/firmador
================

A PHP library for XML Security Hacienda

1.0.2(8mo ago)0481↓80%BSD-3-ClausePHPPHP &gt;= 5.4

Since Apr 9Pushed 8mo agoCompare

[ Source](https://github.com/asystec-cr/xmlseclibs_hacienda)[ Packagist](https://packagist.org/packages/asystec/firmador)[ RSS](/packages/asystec-firmador/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (4)Used By (0)

\#xmlseclibs

xmlseclibs is a library written in PHP for working with XML Encryption and Signatures.

The author of xmlseclibs is Rob Richards.

Requirements
============

[](#requirements)

xmlseclibs requires PHP version 5.4 or greater. **5.6.24+ recommended for security reasons**

How to Install
--------------

[](#how-to-install)

```
composer require "asystec/firmador"
```

Use cases
---------

[](#use-cases)

xmlseclibs is being used in many different software.

- [SimpleSAMLPHP](https://github.com/simplesamlphp/simplesamlphp)
- [LightSAML](https://github.com/lightsaml/lightsaml)
- [OneLogin](https://github.com/onelogin/php-saml)

Basic usage
-----------

[](#basic-usage)

The example below shows basic usage of xmlseclibs, with a SHA-256 signature.

```
use JRTEC\XMLSecLibs_Hacienda\XMLSecurityDSig;
use JRTEC\XMLSecLibs_Hacienda\XMLSecurityKey;

class Firmador {

    const FROM_XML_STRING = 1;
    const FROM_XML_FILE = 2;
    const TO_BASE64_STRING = 3;
    const TO_XML_STRING = 4;
    const TO_XML_FILE = 5;

    public function firmarXml($pfx,$pin,$input,$output,$path=null){

        // Cargar un nuevo XML para ser firmado
        $xml = new \DOMDocument();

        // Detectar si es un archivo (ruta en disco) o bien un string xml
        if (file_exists($input)){
            $input = file_get_contents($input);
        }

        // Intentar parsear el input como archivo xml. Caso contrario se detiene el script
        try {
            $xml->loadXML($input);
        } catch (\Exception $ex){
            die($ex->getMessage());
        }

        // Crear un nuevo objeto de seguridad
        $objSec = new XMLSecurityDSig();

        // Mantener el primer nodo secundario original XML en memoria
        $objSec->xmlFirstChild = $xml->firstChild;

        // Establecer política de firma
        $objSec->setSignPolicy();

        // Cargar la información del certificado desde el archivo *.p12
        $certInfo = $objSec->loadCertInfo($pfx,$pin);

        // Usar la canonicalización exclusiva de c14n.
        $objSec->setCanonicalMethod($objSec::C14N);

        // Cargar la clave privada del certificado
        $objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, array('type' => 'private'));
        $objKey->loadKey($certInfo["privateKey"]);

        // Agregar la clave pública asociada a la firma.
        $objSec->add509Cert($certInfo["publicKey"], true);
        $objSec->appendKeyValue($certInfo);

        // Insertar objeto Xades en la firma.
        $objSec->appendXades($certInfo);

        // Firmar utilizando SHA-256
        // Referencia del documento
        $objSec->addReference($xml,$objSec::SHA256, [ 'http://www.w3.org/2000/09/xmldsig#enveloped-signature' ], [ 'id_ref' => $objSec->reference0Id, 'force_uri' => true ]);

        // Referencia de nodo de información clave
        $objSec->addReference($objSec->getKeyInfoNode(),$objSec::SHA256,null, [ 'id_ref' => $objSec->reference1Id, 'force_uri' => false, 'overwrite' => false ]);

        // Referencia del nodo Xades
        $objSec->addReference($objSec->getXadesNode(),$objSec::SHA256,null, [ 'force_uri' => false, 'overwrite' => false, "type" => "http://uri.etsi.org/01903#SignedProperties" ], [ [ 'qualifiedName' => 'xmlns:xades', 'value' => $objSec::XADES ] ]);

        // Firma el archivo xml
        $objSec->sign($objKey);

        // Adjuntar la firma al xml
        $objSec->appendSignature($xml->documentElement);

        if ($output == self::TO_BASE64_STRING){
            // Devuelve el string del archivo xml firmado en formato Base64
            return base64_encode($xml->saveXML());
        } else if ($output == self::TO_XML_STRING){
            // Devuelve el archivo xml firmado en formato string Xml
            return $xml->saveXML();
        } else if ($output == self::TO_XML_FILE){
            // Guarda el xml firmado en la ruta especificada y devuelve el resultado
            if (!is_null($path)) {
                return $xml->save($path);
            } else {
                return false;
            }
        }
    }
}
```

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance60

Regular maintenance activity

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~803 days

Total

3

Last Release

253d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/99a01dca629b77c98577054b22020718d05d43d1eb37580494ef1584fd91984a?d=identicon)[bvalerin](/maintainers/bvalerin)

---

Top Contributors

[![bvalerin](https://avatars.githubusercontent.com/u/12622573?v=4)](https://github.com/bvalerin "bvalerin (8 commits)")[![Rastian95](https://avatars.githubusercontent.com/u/25542844?v=4)](https://github.com/Rastian95 "Rastian95 (4 commits)")

---

Tags

xmlsecuritysignaturexmldsighacienda CR

### Embed Badge

![Health badge](/badges/asystec-firmador/health.svg)

```
[![Health](https://phpackages.com/badges/asystec-firmador/health.svg)](https://phpackages.com/packages/asystec-firmador)
```

###  Alternatives

[robrichards/xmlseclibs

A PHP library for XML Security

41278.1M118](/packages/robrichards-xmlseclibs)[greenter/xmldsig

Libreria para firmar XML según normativa de SUNAT en Facturación Electrónica

38794.6k9](/packages/greenter-xmldsig)[ass/xmlsecurity

The XmlSecurity library is written in PHP for working with XML Encryption and Signatures

955.6M30](/packages/ass-xmlsecurity)[fr3d/xmldsig

Tool for easy management of XML Signatures (http://www.w3.org/TR/xmldsig-core/)

63150.6k1](/packages/fr3d-xmldsig)[lyquidity/xml-signer

A PHP to create and verify XAdES signature

2164.6k1](/packages/lyquidity-xml-signer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
