OpenSSL Module (PHP)

Table of Contents

  1. Description
    1. Public Methods
      1. Demo

        Description

        The SetaPDF_Signer_Signature_Module_OpenSsl module makes use of the PHP build-in OpenSSL function openssl_pkcs7_sign() to create the signature.

        The function uses the SHA-1 digest algorithm (as documentated on php.net) or SHA-256 depending on the OpenSSL version installed on the server you are using. After all you have no control over the digest algorithm!

        The certificate and private key data has to be passed as described here.

        Public Methods

        getCertificate()

        Get the certificate parameter.

        getExtraCertificates()

        Get the extra certificate parameter.

        getPrivateKey()

        Get the private key parameter

        setCertificate()

        Set the certificate parameter.

        setExtraCertificates()

        Set the extra certificate parameter.

        setPrivateKey()

        Set the private key parameter.

        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/lenstown/Laboratory-Report.pdf', $writer
        );
        
        // create a signer instance
        $signer = new \SetaPDF_Signer($document);
        
        // set some signature properties
        $signer->setReason('Testing OpenSSL module');
        $signer->setLocation('SetaPDF-Signer Manual');
        
        // create a signature module
        $module = new \SetaPDF_Signer_Signature_Module_OpenSsl();
        // load the certificate
        $certificate = 'file://files/certificates/setapdf-no-pw.pem';
        $module->setCertificate($certificate);
        $module->setPrivateKey(array($certificate, '' /* no password */));
        
        // sign the document and send the final document to the initial writer
        $signer->sign($module);