OpenSSL S/MIME Module (CLI)

Table of Contents

  1. Description
    1. Public Methods
      1. Demo

        Description

        The \setasign\SetaPDF2\Signer\Signature\Module\OpenSslCli module uses the S/MIME utility of OpenSSL to create the signature. 

        It allows you e.g. to define a specifc digest algorithm.  

        The utility will be executed by an exec() call.

        Public Methods

        getCertificate()

        Get the path to the signing certificate.

        getDigest()

        Get the digest algorithm.

        getExtraCertificates()

        Get the path of the file with additional certificates.

        getOpenSslPath()

        Get the path to the openssl binary.

        getPrivateKey()

        Get the path to the private key file.

        getPrivateKeyPassword()

        Get the private key password source.

        setCertificate()

        Set the path to the signing certificate.

        setDigest()

        Set the digest algorithm to use when signing.

        setExtraCertificates()

        Set the path to a file with additional certificates which will be included in the signature.

        setOpenSslPath()

        Set the path to the openssl binary.

        setPrivateKey()

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

        setPrivateKeyPassword()

        Set the private key password source.

        Demo

        PHP
        <?php
        
        use setasign\SetaPDF2\Core\Document;
        use setasign\SetaPDF2\Core\Writer\HttpWriter;
        use setasign\SetaPDF2\Signer\Signature\Module\OpenSslCli as OpenSslCliModule;
        use setasign\SetaPDF2\Signer\Signer;
        
        require_once('library/SetaPDF/Autoload.php');
        
        // create a writer
        $writer = new HttpWriter('simple.pdf', true);
        // create a new document instance
        $document = Document::loadByFilename(
            'files/pdfs/tektown/Laboratory-Report.pdf', $writer
        );
        
        // create a signer instance
        $signer = new Signer($document);
        
        // set some signature properties
        $signer->setReason('Testing CMS module');
        $signer->setLocation('SetaPDF-Signer Manual');
        
        // create a signature module
        $module = new OpenSslCliModule();
        // load the certificate
        $certificate = 'files/certificates/setapdf-no-pw.pem';
        $module->setCertificate($certificate);
        $module->setPrivateKey($certificate, '' /* no password */);
        
        // sign the document and send the final document to the initial writer
        $signer->sign($module);