Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

DsigSdk

  • PHP SDK of XML Digital Signature recommendation
  • based on the XSD schema

and provide

  • dto's for all element(type)s in XSD

    • with getters and setters, no other logic
  • parse of XML into dto(s)

  • write of dto(s) to XML string / DomNode

  • logic support

Usage, parse XML

To parse an Dsig (Signature root) XML file (using XMLReader) :

<?php
namespace Kigkonsult\DsigSdk;
use Kigkonsult\DsigSdk\XMLParse\DsigParser;

$dsig = DsigParser::factory()->parse( 
    file_get_contents( 'DsigFile.xml' )
);

$signedInfo = $dsig->getsignedInfo();
...

The XML parser save the XMLreader node properties (baseURI, localName, name, namespaceURI, prefix) for each XML (Dto) element as 'XMLattributes' as well as XML attributes (xmlns, xmlns:*, schemaLocation), if set (more info below).

'any' XSD elements are accepted as 'Anytype' object instances (more info below, 'AnyType').

Usage, build up structure

To build up dsig structure:

<?php
namespace Kigkonsult\DsigSdk;
use Kigkonsult\DsigSdk\Dto\Any;
use Kigkonsult\DsigSdk\Dto\CanonicalizationMethod;
use Kigkonsult\DsigSdk\Dto\KeyInfo;
use Kigkonsult\DsigSdk\Dto\SignedInfo;
use Kigkonsult\DsigSdk\Dto\Signature;
use Kigkonsult\DsigSdk\Dto\SignatureValue;
use Kigkonsult\DsigSdk\Dto\X509Data;

$dsig = Signature::factory()
    ->setSignedInfo( 
        SignedInfo::factory()
            ->setCanonicalizationMethod(
                CanonicalizationMethod::factory()
                    ->setAlgorithm( 'algorithm' )
                    ->setAny( [
                        Any::factory()
                            ->setElementName( 'nonSchemaElement1')
                            ->setAttributes( [
                                'id' => '12345' 
                                ] )
                             ->setContent( 'Lr1mKGxP7VAgMB...' ),
                        Any::factory()
                            ->setElementName( 'nonSchemaElement2')
                            ->setAny( [
                                Any::factory()
                                    ->setElementName( 'nonSchemaElement3')
                                    ->setContent( 'Lr1mKGxP7VAgMB...' ),
                            ] )
                        ]
                    )
            )
    )
    ->setSignatureValue(
        SignatureValue::factory()
            ->setSignatureValueType( 'vgGZnRlm8...' )
    )
    ->setKeyInfo(
        KeyInfo::factory()
            ->setKeyInfoType( [
                [                 // one set of elements
                    [             // element
                        X509Data::X509DATA => 
                            X509Data::factory()
                                ->setX509DataTypes( ... )
                    ],
                ],
        ] )
    )
    ->setObject(
        ...
    )
    ...
XML attributes

You can set (single 'element') XMLattribute using

$dsig->setXMLAttribut( <key>, <value> );

To set (ex. prefix) and 'propagate' down in hierarchy:

$dsig->setXMLAttribut( SignatureType::PREFIX, <value>, true );

You can remove (single 'element') XMLattribute using

$dsig->unsetXMLAttribut( <key> );

To unset (ex. prefix) and 'propagate' down in hierarchy:

$dsig->unsetXMLAttribut( SignatureType::PREFIX, true );

To fetch and iterate over XMLAttributes

foreach( $dsig->getXMLAttributes() as $key => $value {
    ...
}
Anytype

Anytype object instances are used for 'any' XSD elements. The element name are stored and fetched with

$anytype->setElementName( <name> );
$anytypeName = $anytype->getElementName();

The 'any' XSD element attributes may include XML attributes.

The AnyType attributes are stored and fetched as array.

$anytype->setAttributes( [ <key> => <value> ] );
foreach( $anytype->getAttributes() as $key => $value {
    ...
}

Note, an AnyType instance may have

  • content
    • type string,
    • AnyType::setContent()
    • AnyType::getContent()

or

  • sub-elements
    • type array [*AnyType]
    • AnyType::setAny()
    • AnyType::getAny()

but not both.

Usage, output as XML

DsigSdk uses XMLWriter creating output.

$XMLstring = DsigWriter::factory()->write( $dsig );

The XMLwriter adds for each element

  • element name with prefix, if exists
  • XMLattribute xmlns, xmlns:* and schemaLocation, if exists.

Usage, output as DomNode

$domNode = DsigWriter::factory()->write( $dsig, true );

Info

For class structure and architecture, please review

You may find convenient constants in

For base64Encode/base64Decode/hash etc support, please review OpenSSLToolbox

Installation

Composer

From the Command Line:

composer require kigkonsult/dsigsdk

In your composer.json:

{
    "require": {
        "kigkonsult/dsigsdk": "dev-master"
    }
}

Version 1.4 supports PHP 8.0, 1.2 7.4, 1.0 7.0.

Acquire access

namespace Kigkonsult\DsigSdk;
...
include 'vendor/autoload.php';
Or

Download and acquire..

namepace Kigkonsult\DsigSdk;
...
include 'pathToSource/DsigSdk/autoload.php';

Support

For support, please use Github/issues.

License

This project is licensed under the LGPLv3 License

About

XML Digital Signature recomendation dsig sdk

Resources

Sponsor this project

Packages

No packages published

Languages