PHP code example of komma-softhouse / asice-engine

1. Go to this page and download the library: Download komma-softhouse/asice-engine 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/ */

    

komma-softhouse / asice-engine example snippets


use Komma\Asice\Container\UnsignedContainer;
use Komma\Asice\Crypto\SignAlg;

$container = UnsignedContainer::make()
    ->addFile('invoice.pdf', $pdf, 'application/pdf')
    ->addFile('invoice.xml', $xml, 'application/xml')
    ->build('/tmp/invoice.asice');

$pending = $container->createSignature($certificateBase64, SignAlg::SHA256, city: 'Tallinn', country: 'EE');

$hash = $pending->getHashBase64();   // what the card or the phone signs
$state = $pending->serialize();      // survives a session, a queue or a database row

use Komma\Asice\Container\Container;
use Komma\Asice\Signature\PendingSignature;

$container = Container::open('/tmp/invoice.asice');
$result = $container->finishSignature(PendingSignature::unserialize($state), $signatureValue);
$container->save();

$result['long_term'];   // true when both the time-stamp and the OCSP answer were obtained
$result['notes'];       // what could not be reached, if anything

$result = Container::open($path)->validate();

$result->isValid();

foreach ($result->signatures() as $signer) {
    $signer->name();          // "TESTPERE TESTNIMI"
    $signer->personalCode();  // "38001085718"
    $signer->signedAt();      // DateTimeImmutable
    $signer->isLongTerm();    // time-stamp + OCSP answer present
    $signer->errors();
}

use Komma\Asice\Ocsp\OcspClient;
use Komma\Asice\Tsa\TimestampClient;

$container->using(
    ocsp: new OcspClient(timeout: 15),
    tsa: new TimestampClient('http://tsa.example.org'),
    issuer: $issuerCertificate,
);