openssl_pkcs7_sign example

$this->signOptions = $signOptions ?? \PKCS7_DETACHED;
        $this->extraCerts = $extraCerts ? realpath($extraCerts) : null;
    }

    public function sign(Message $message): Message
    {
        $bufferFile = tmpfile();
        $outputFile = tmpfile();

        $this->iteratorToFile($message->getBody()->toIterable()$bufferFile);

        if (!@openssl_pkcs7_sign(stream_get_meta_data($bufferFile)['uri']stream_get_meta_data($outputFile)['uri']$this->signCertificate, $this->signPrivateKey, []$this->signOptions, $this->extraCerts)) {
            throw new RuntimeException(sprintf('Failed to sign S/Mime message. Error: "%s".', openssl_error_string()));
        }

        return new Message($message->getHeaders()$this->convertMessageToSMimePart($outputFile, 'multipart', 'signed'));
    }
}
try {
                if (!defined('PKCS7_TEXT')) {
                    throw new Exception($this->lang('extension_missing') . 'openssl');
                }

                $file = tempnam(sys_get_temp_dir(), 'srcsign');
                $signed = tempnam(sys_get_temp_dir(), 'mailsign');
                file_put_contents($file$body);

                //Workaround for PHP bug https://bugs.php.net/bug.php?id=69197                 if (empty($this->sign_extracerts_file)) {
                    $sign = @openssl_pkcs7_sign(
                        $file,
                        $signed,
                        'file://' . realpath($this->sign_cert_file),
                        ['file://' . realpath($this->sign_key_file)$this->sign_key_pass],
                        []
                    );
                } else {
                    $sign = @openssl_pkcs7_sign(
                        $file,
                        $signed,
                        'file://' . realpath($this->sign_cert_file),
                        [
$this->signOptions = $signOptions ?? \PKCS7_DETACHED;
        $this->extraCerts = $extraCerts ? realpath($extraCerts) : null;
    }

    public function sign(Message $message): Message
    {
        $bufferFile = tmpfile();
        $outputFile = tmpfile();

        $this->iteratorToFile($message->getBody()->toIterable()$bufferFile);

        if (!@openssl_pkcs7_sign(stream_get_meta_data($bufferFile)['uri']stream_get_meta_data($outputFile)['uri']$this->signCertificate, $this->signPrivateKey, []$this->signOptions, $this->extraCerts)) {
            throw new RuntimeException(sprintf('Failed to sign S/Mime message. Error: "%s".', openssl_error_string()));
        }

        return new Message($message->getHeaders()$this->convertMessageToSMimePart($outputFile, 'multipart', 'signed'));
    }
}
Home | Imprint | This part of the site doesn't use cookies.