PAdES Module (PHP)

Table of Contents

  1. Description
    1. Public Methods
      1. Demo

        Description

        The \setasign\SetaPDF2\Signer\Signature\Module\Pades module allows you to create PAdES-BES/B-B conform signatures.

        PAdES (PDF Advanced Electronic Signatures) is a set of restrictions and extensions to PDF and ISO 32000-1 making it suitable for advanced electronic signature. This is published by ETSI as TS 102 778.

        The PAdES-BES/B-B profile defines an optional signature-timestamp-stamp attribute. This can be used by simply combining this signature module with an additional timestamp module to get PAdES B-T level.

        When adding revocation information to the signed document it is possible to get PAdES B-LT level.
        Appending an additional document level timestamp will end in PAdES B-LTA level.

        This module extends the CMS module to add additional required singed attributes to the CMS structure. Additionally it also have restrictions on the used digest algorithm: It explicitly prohibits the usage of MD5, SHA-1 or RIPEMD-160.

        Public Methods

        addCrl()

        Adds an CRL which will be embedded in the CMS structure.

        addOcspResponse()

        Adds an OCSP response which will be embedded in the CMS structure.

        addSigningCertificateV2()

        Adds Signing Certificate Reference Attribute.

        getCertificate()

        Get the certificate value.

        getCms()

        Get the complete Cryptographic Message Syntax structure.

        getDataToSign()

        Get the data which needs to be digitally signed.

        getDigest()

        Get the digest algorithm.

        getParsedCertificate()

        Ensures a certificate parameter and parses it into an ASN.1 element object structure.

        setCertificate()

        Set the signing certificate.

        setDigest()

        Set the digest algorithm to use when signing.

        setExtraCertificates()

        Add additional certificates which are placed into the CMS structure.

        setOcspResponse()

        Alias for addOcspResponse().

        setPrivateKey()

        Set the the private key or a path to the private key file and password argument.

        setSignatureValue()

        Set the signature value.

        Demo

        PHP
        <?php
        
        use setasign\SetaPDF2\Core\Document;
        use setasign\SetaPDF2\Core\Writer\HttpWriter;
        use setasign\SetaPDF2\Signer\Signature\Module\Pades as PadesModule;
        use setasign\SetaPDF2\Signer\Signer;
        use setasign\SetaPDF2\Signer\Timestamp\Module\Rfc3161\Curl as CurlTimestampModule;
        
        require_once('library/SetaPDF/Autoload.php');
        
        // create a writer
        $writer = new HttpWriter('PAdES-with-timestamp.pdf', true);
        // create a new document instance
        $document = Document::loadByFilename(
            'files/pdfs/etown/Laboratory-Report.pdf', $writer
        );
        
        // create a signer instance
        $signer = new Signer($document);
        
        // set some signature properties
        $signer->setReason('Testing PAdES module');
        $signer->setLocation('SetaPDF-Signer Manual');
        
        // We need more space, if the signature will include a timestamp signature
        $signer->setSignatureContentLength(18000);
        
        // create a signature module
        $module = new PadesModule();
        // load the certificate
        $certificate = 'file://files/certificates/setapdf-no-pw.pem';
        $module->setCertificate($certificate);
        $module->setPrivateKey([$certificate, '' /* no password */]);
        
        // create a timestamp module
        $tsModule = new CurlTimestampModule('http://zeitstempel.dfn.de');
        $signer->setTimestampModule($tsModule);
        
        // sign the document and send the final document to the initial writer
        $signer->sign($module);