lib/classes/Swift/Signers/SMimeSigner.php
protected function smimeEncryptMessage(Swift_Message $message)
    {
        // If we don't have a certificate we can't encrypt the message
        if (null === $this->encryptCert) {
            return;
        }

        // Work on a clone of the original message
        $encryptMessage = clone $message;
        $encryptMessage->clearSigners();

        if ($this->wrapFullMessage) {
            // The original message essentially becomes the body of the new
            // wrapped message
            $encryptMessage = $this->wrapMimeMessage($encryptMessage);
        } else {
            // Only keep header needed to parse the body correctly
            $this->clearAllHeaders($encryptMessage);
            $this->copyHeaders(
                $message,
                $encryptMessage,
                [
                    'Content-Type',
                    'Content-Transfer-Encoding',
                    'Content-Disposition',
                ]
            );
        }

        // Convert the message content (including headers) to a string
        // and place it in a temporary file
        $messageStream = new Swift_ByteStream_TemporaryFileByteStream();
        $encryptMessage->toByteStream($messageStream);
        $messageStream->commit();
        $encryptedMessageStream = new Swift_ByteStream_TemporaryFileByteStream();

        // Encrypt the message
        if (!openssl_pkcs7_encrypt(
                $messageStream->getPath(),
                $encryptedMessageStream->getPath(),
                $this->encryptCert,
                [],
                0,
                $this->encryptCipher
            )
        ) {
            throw new Swift_IoException(sprintf('Failed to encrypt S/Mime message. Error: "%s".', openssl_error_string()));
        }

        // Parse the resulting signed message content back into the Swift message
        // preserving the original headers
        $this->parseSSLOutput($encryptedMessageStream, $message);
    }
protected function smimeEncryptMessage(Swift_Message $message)
    {
        // If we don't have a certificate we can't encrypt the message
        if (null === $this->encryptCert) {
            return;
        }

        // Work on a clone of the original message
        $encryptMessage = clone $message;
        $encryptMessage->clearSigners();

        if ($this->wrapFullMessage) {
            // The original message essentially becomes the body of the new
            // wrapped message
            $encryptMessage = $this->wrapMimeMessage($encryptMessage);
        } else {
            // Only keep header needed to parse the body correctly
            $this->clearAllHeaders($encryptMessage);
            $this->copyHeaders(
                $message,
                $encryptMessage,
                [
                    'Content-Type',
                    'Content-Transfer-Encoding',
                    'Content-Disposition',
                ]
            );
        }

        // Convert the message content (including headers) to a string
        // and place it in a temporary file
        $messageStream = new Swift_ByteStream_TemporaryFileByteStream();
        $encryptMessage->toByteStream($messageStream);
        $messageStream->commit();
        $encryptedMessageStream = new Swift_ByteStream_TemporaryFileByteStream();

        // Encrypt the message
        if (!openssl_pkcs7_encrypt(
                $messageStream->getPath(),
                $encryptedMessageStream->getPath(),
                $this->encryptCert,
                [],
                0,
                $this->encryptCipher
            )
        ) {
            throw new Swift_IoException(sprintf('Failed to encrypt S/Mime message. Error: "%s".', openssl_error_string()));
        }

        // Parse the resulting signed message content back into the Swift message
        // preserving the original headers
        $this->parseSSLOutput($encryptedMessageStream, $message);
    }
protected function smimeEncryptMessage ( Swift_Message $ message ) { // If we don't have a certificate we can't encrypt the message if ( null === $ this -> encryptCert ) { return ; } // Work on a clone of the original message $ encryptMessage = clone $ message ; $ encryptMessage -> clearSigners ( ) ; if ( $ this -> wrapFullMessage ) { // The original message essentially becomes the body of the new // wrapped message $ encryptMessage = $ this -> wrapMimeMessage ( $ encryptMessage ) ; } else { // Only keep header needed to parse the body correctly $ this -> clearAllHeaders ( $ encryptMessage ) ; $ this -> copyHeaders ( $ message , $ encryptMessage , [ 'Content-Type' , 'Content-Transfer-Encoding' , 'Content-Disposition' , ] ) ; } // Convert the message content (including headers) to a string // and place it in a temporary file $ messageStream = new Swift_ByteStream_TemporaryFileByteStream ( ) ; $ encryptMessage -> toByteStream ( $ messageStream ) ; $ messageStream -> commit ( ) ; $ encryptedMessageStream = new Swift_ByteStream_TemporaryFileByteStream ( ) ; // Encrypt the message if ( ! openssl_pkcs7_encrypt ( $ messageStream -> getPath ( ) , $ encryptedMessageStream -> getPath ( ) , $ this -> encryptCert , [ ] , 0 , $ this -> encryptCipher ) ) { throw new Swift_IoException ( sprintf ( 'Failed to encrypt S/Mime message. Error: "%s".' , openssl_error_string ( ) ) ) ; } // Parse the resulting signed message content back into the Swift message // preserving the original headers $ this -> parseSSLOutput ( $ encryptedMessageStream , $ message ) ; }
Encrypt a Swift message.
Encrypt a Swift message .