Symfony 4.4 New Features Preview: sign and encrypt e-mail

Symfony 4.4 will be released in November 2019. The official released the first series of articles on the article , describes the most important new features introduced in this version of Symfony.

Symfony 4.3 introduced a new Mailer and Mime components, based SwiftMailer solutions before replacing. In Symfony 4.4, the development team to use its new features has been improved to allow the use of S / MIME standard for email signing and encryption.

Signing a message may increase its integrity, because it includes the entire contents of the e-mail digitally signed hash value, thereby ensuring that the original content is not modified:

use Symfony\Component\Mime\Crypto\SMimeSigner;
use Symfony\Component\Mime\Email;

$email = (new Email())->from('...')->to('...')->html('...');

$signer = new SMimeSigner('/path/to/certificate.crt', '/path/to/certificate-private-key.key');
$signedEmail = $signer->sign($email);
// now use the Mailer to send this $signedEmail instead of the original $email

Encrypted messages can improve their safety, because only contains a public key and a private key used to encrypt the associated message to read its contents (including any attachments):

use Symfony\Component\Mime\Crypto\SMimeEncrypter;
use Symfony\Component\Mime\Email;

$email = (new Email())->from('...')->to('...')->html('...');

$encrypter = new SMimeEncrypter('/path/to/certificate.crt');
$encryptedEmail = $encrypter->encrypt($email);
// now use the Mailer to send this $encryptedEmail instead of the original $email

Symfony can be found in the official document " signing and encrypting messages " article for more information about this feature.

Guess you like

Origin www.oschina.net/news/110518/new-in-symfony-4-4-signing-and-encrypting-email-messages