PAdES Module (PHP)

Table of Contents

  1. Description
    1. Public Methods
      1. Demo

        Description

        The SetaPDF_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.  

        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

        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 (PEM).

        setDigest()

        Set the digest algorithm to use when signing.

        setExtraCertificates()

        Add additional certificates which are placed into the CMS structure.

        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
        require_once('library/SetaPDF/Autoload.php');
        
        // create a writer
        $writer = new SetaPDF_Core_Writer_Http('simple.pdf', true);
        // create a new document instance
        $document = SetaPDF_Core_Document::loadByFilename(
            'files/pdfs/etown/Laboratory-Report.pdf', $writer
        );
        
        // create a signer instance
        $signer = new SetaPDF_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(10000);
        
        // create a signature module
        $module = new SetaPDF_Signer_Signature_Module_Pades();
        // load the certificate
        $certificate = 'file://files/certificates/setapdf-no-pw.pem';
        $module->setCertificate($certificate);
        $module->setPrivateKey(array($certificate, '' /* no password */));
        
        // create a timestamp module
        $tsModule = new SetaPDF_Signer_Timestamp_Module_Rfc3161_Curl();
        $tsModule->setUrl('http://zeitstempel.dfn.de');
        $signer->setTimestampModule($tsModule);
        
        // sign the document and send the final document to the initial writer
        $signer->sign($module);