PHPackages                             metalback/xmldsig - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. metalback/xmldsig

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

metalback/xmldsig
=================

Fork of Selective\\XmlDSig for Sign XML Documents with Digital Signatures

2.2.1.1(4y ago)029MITPHPPHP ^7.2 || ^8.0

Since Aug 1Pushed 4y agoCompare

[ Source](https://github.com/metalback/xmldsig)[ Packagist](https://packagist.org/packages/metalback/xmldsig)[ Docs](https://github.com/metalback/xmldsig)[ RSS](/packages/metalback-xmldsig/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (5)Versions (14)Used By (0)

XMLDSIG for PHP
===============

[](#xmldsig-for-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/63587ec95a33c2112c0d60aec4d6b2273a1bc2676b50a534eea3b3ac24bc0709/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f73656c6563746976652d7068702f786d6c647369672e737667)](https://packagist.org/packages/selective/xmldsig)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://github.com/selective-php/xmldsig/workflows/build/badge.svg)](https://github.com/selective-php/xmldsig/actions)[![Coverage Status](https://camo.githubusercontent.com/4bb128dd3bdee07cca7a2736dc11d59b1e1f4dc051f4ae86dfe37d5c95d23a61/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f73656c6563746976652d7068702f786d6c647369672e737667)](https://scrutinizer-ci.com/g/selective-php/xmldsig/code-structure)[![Quality Score](https://camo.githubusercontent.com/1e835d042f45065f9c6e9dcf3346a9fc0b0a0269a1509a6378a9278b4bcbbdf5/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f73656c6563746976652d7068702f786d6c647369672e737667)](https://scrutinizer-ci.com/g/selective-php/xmldsig/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/8bb62cbc516a6169b5e20da4ce82078eb496ff53bb3cabc474a1a22f4cf09c93/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73656c6563746976652f786d6c647369672e737667)](https://packagist.org/packages/selective/xmldsig/stats)

Features
--------

[](#features)

- Sign XML Documents with Digital Signatures ([XMLDSIG](https://www.w3.org/TR/xmldsig-core/))
- Verify the Digital Signatures of XML Documents

Requirements
------------

[](#requirements)

- PHP 7.2+ or 8.0+
- The openssl extension
- A X.509 digital certificate

Installation
------------

[](#installation)

```
composer require selective/xmldsig

```

Usage
-----

[](#usage)

### Sign XML Document with Digital Signature

[](#sign-xml-document-with-digital-signature)

Input file: example.xml

```

        19834209
        02/02/2025

```

```
use Selective\XmlDSig\DigestAlgorithmType;
use Selective\XmlDSig\XmlSigner;

$xmlSigner = new XmlSigner();

$xmlSigner->loadPfxFile('filename.pfx', 'password');

// or load pfx from a string
//$xmlSigner->loadPfx('pfx content', 'password');

// or load a PEM file
//$xmlSigner->loadPrivateKeyFile('filename.pem', 'password');

// or load a PEM private key from a string
//$xmlSigner->loadPrivateKey('private key content', 'password');

// Optional: Set reference URI
$xmlSigner->setReferenceUri('');

$xmlSigner->signXmlFile('example.xml', 'signed-example.xml', DigestAlgorithmType::SHA512);
```

Output file: signed-example.xml

```

        19834209
        02/02/2025

                Base64EncodedValue==

        AnotherBase64EncodedValue===

```

### Verify the Digital Signatures of XML Documents

[](#verify-the-digital-signatures-of-xml-documents)

```
use Selective\XmlDSig\XmlSignatureValidator;

// Create a validator instance
$signatureValidator = new XmlSignatureValidator();
```

```
// Load a PFX file
$signatureValidator->loadPfxFile('filename.pfx', 'password');

// or load just a public key file from a string
$signatureValidator->loadPfx('public key content', 'password');

// or load a public key file (without password)
$signatureValidator->loadPublicKeyFile('cacert.pem');

// or load the public key from a string (without password)
$signatureValidator->loadPublicKey('public key content');
```

```
// Verify a XML file
$isValid = $signatureValidator->verifyXmlFile('signed-example.xml');

// or verify XML from a string
$isValid = $signatureValidator->verifyXml('xml content');

if ($isValid === true) {
    echo 'The XML signature is valid.';
} else {
    echo 'The XML signature is not valid.';
}
```

### Online XML Digital Signature Verifier

[](#online-xml-digital-signature-verifier)

Try these excellent online tools to verify XML signatures:

-
-

Similar libraries
-----------------

[](#similar-libraries)

-

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 97% 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 ~100 days

Recently: every ~69 days

Total

13

Last Release

1634d ago

Major Versions

0.4.0 → 1.0.02020-02-25

1.0.0 → 2.0.02021-02-13

PHP version history (2 changes)0.1.0PHP ^7.1.3

2.0.0PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/e3749b58f2f3312bda33bdd0efd6aa98946fbc16cc7522d02bd8ea06803aeb13?d=identicon)[metalback](/maintainers/metalback)

---

Top Contributors

[![odan](https://avatars.githubusercontent.com/u/781074?v=4)](https://github.com/odan "odan (64 commits)")[![mbeltran-indap](https://avatars.githubusercontent.com/u/68286555?v=4)](https://github.com/mbeltran-indap "mbeltran-indap (2 commits)")

---

Tags

xmlverifyxmldsigsignatures

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/metalback-xmldsig/health.svg)

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M226](/packages/masterminds-html5)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M849](/packages/jms-serializer)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M619](/packages/jms-serializer-bundle)[sabre/xml

sabre/xml is an XML library that you may not hate.

52832.2M131](/packages/sabre-xml)[presta/sitemap-bundle

A Symfony bundle that provides tools to build your application sitemap.

3929.4M28](/packages/presta-sitemap-bundle)

PHPackages © 2026

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