PHP code example of andreygrin / xades-tools

1. Go to this page and download the library: Download andreygrin/xades-tools 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/ */

    

andreygrin / xades-tools example snippets


use XadesTools\CertificateFactory;
use XadesTools\Signature;
$cert = CertificateFactory::string(
    $privateKeyContents, // .pem
    $certificateContents, // .crt
    $parivateKeyPassword // string
);

$this->signer = new Signature($cert);
$this->signer->signXml('xmlContent') // returns signature, you should add it to the xml file the way you need to have it there.

use XadesTools\Verification;
$xades = new Verification();
$result = $xades->verifyFile($pathToXadesFile);
if ($result) {
    $content = $res->content; // binary content or plain text for xml files
    $signTime = $res->dateSigned; // DateTime object
    $signingSubject = $res->signingSubject; // array
} else {
    // Signature does not match signed content
}
shell
php bin/sign.php file cert pass [embed] [load-content]
shell
php src/verify.php file [verbose]
shell
php src/extract.php file output