Symfony 4.4 新功能预览:对电子邮件进行签名和加密

 邮箱网  0条评论  4109次浏览  2019年10月15日 星期二 09:54

分享到: 更多

中国邮箱网讯 10月15日消息 Symfony 4.4 将于 2019 年 11 月发布。官方发布了关于该系列的第一篇文章,介绍了此 Symfony 版本引入的最重要的新功能。

Symfony 4.3 中引入了新的 Mailer 和 Mime 组件,以取代之前基于 SwiftMailer 的解决方案。在 Symfony 4.4 中,开发团队使用新功能对其进行了改进,以允许使用 S/MIME 标准对电子邮件进行签名和加密。

对消息进行签名可以提高其完整性,因为它包括整个电子邮件内容的哈希值的数字签名,从而确保原始内容没有被修改:

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

加密消息可提高其安全性,因为只有包含与用于加密消息的公共密钥相关联的私有密钥,才能读取其内容(包括任何附件):

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

我的评论:

请  后发表评论。