paragonie/gpg-mailer
最新稳定版本:v0.6.1
Composer 安装命令:
composer require paragonie/gpg-mailer
包简介
Encrypt outbound emails with Crypt_GPG
关键字:
README 文档
README
Send GPG-encrypted emails (using zend-mail and Crypt_GPG).
License: MIT
The GPG-Mailer API in a Nutshell
/** * Import a public key, return the fingerprint * * @param string $gpgKey An ASCII armored public key * @return string The GPG fingerprint for this key */ public function import(string $gpgKey): string; /** * Get the public key corresponding to a fingerprint. * * @param string $fingerprint * @return string */ public function export(string $fingerprint): string; /** * Encrypt then email a message * * @param Message $message The message data * @param string $fingerprint Which public key fingerprint to use */ public function send(Message $message, string $fingerprint); /** * Email a message without encrypting it. * * @param Message $message The message data * @param bool $force Send even if we don't have a private key? */ public function sendUnencrypted(Message $message, bool $force = false);
Example: Encrypt Outbound Emails with Your GnuPG Public Key
<?php use \ParagonIE\GPGMailer\GPGMailer; use \Zend\Mail\Message; use \Zend\Mail\Transport\Sendmail; // First, create a Zend\Mail message as usual: $message = new Message; $message->addTo('test@example.com', 'Test Email'); $message->setBody('Cleartext for now. Do not worry; this gets encrypted.'); // Instantiate GPGMailer: $gpgMailer = new GPGMailer( new Sendmail(), ['homedir' => '/homedir/containing/keyring'] ); // GPG public key for <security@paragonie.com> (fingerprint): $fingerprint = '7F52D5C61D1255C731362E826B97A1C2826404DA'; // Finally: $gpgMailer->send($message, $fingerprint);
If you're encrypting with a user provided public key (and they didn't tell you their fingerprint), do this instead:
<?php /** * Output from: gpg --armor --export user@example.com * * This is our security team's GPG public key. You probably don't * want to use ours, as only we can decrypt the messages. * * @var string */ $ASCIIArmoredPublicKey = "-----BEGIN PGP PUBLIC KEY BLOCK----- Version: SKS 1.1.5 mQENBFUgwRUBCADcIpqNwyYc5UmY/tpx1sF/rQ3knR1YNXYZThzFV+Gmqhp1fDH5qBs9foh1 xwI6O7knWmQngnf/nBumI3x6xj7PuOdEZUh2FwCG/VWnglW8rKmoHzHAivjiu9SLnPIPAgHS Heh2XD7q3Ndm3nenbjAiRFNl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b1 =Z4m0 -----END PGP PUBLIC KEY BLOCK-----"; // Then to import. $fingerprint = $gpgMailer->import($ASCIIArmoredPublicKey);
Sign Emails with the Server's Private Key
Signed and Encrypted
To add signing, we pass the signing key to the third argument of the GPGMailer constructor.
<?php use \ParagonIE\GPGMailer\GPGMailer; use \Zend\Mail\Message; use \Zend\Mail\Transport\Sendmail; // First, create a Zend\Mail message as usual: $message = new Message; $message->addTo('test@example.com', 'Test Email'); $message->setBody('Cleartext for now. Do not worry; this gets encrypted.'); $signingKey = file_get_contents('tests/private.key'); // Instantiate GPGMailer: $gpgMailer = new GPGMailer( new Sendmail(), ['homedir' => '/homedir/containing/keyring'], $signingKey ); // GPG public key for <security@paragonie.com> (fingerprint): $fingerprint = '7F52D5C61D1255C731362E826B97A1C2826404DA'; // Finally: $gpgMailer->send($message, $fingerprint);
Alternatively, we could define our constructor as above but then use
setPrivateKey() like so:
$gpgMailer = new GPGMailer( new Sendmail(), ['homedir' => '/homedir/containing/keyring'] ); $signingKey = file_get_contents('tests/private.key'); $gpgMailer->setPrivateKey($signingKey);
Signed, But Not Encrypted
Same as above, except we don't need to load the recipient's fingerprint
and we use the sendUnencrypted() method instead.
<?php use \ParagonIE\GPGMailer\GPGMailer; use \Zend\Mail\Message; use \Zend\Mail\Transport\Sendmail; // First, create a Zend\Mail message as usual: $message = new Message; $message->addTo('test@example.com', 'Test Email'); $message->setBody('Cleartext for now. Do not worry; this gets encrypted.'); $signingKey = file_get_contents('tests/private.key'); $gpgMailer = new GPGMailer( new Sendmail(), ['homedir' => '/homedir/containing/keyring'], $signingKey ); $gpgMailer->sendUnencrypted($message);
Support Contracts
If your company uses this library in their products or services, you may be interested in purchasing a support contract from Paragon Initiative Enterprises.
paragonie/gpg-mailer 适用场景与选型建议
paragonie/gpg-mailer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24.91k 次下载、GitHub Stars 达 95, 最近一次更新时间为 2016 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mailer」 「email」 「cryptography」 「gnupg」 「gpg」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 paragonie/gpg-mailer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 paragonie/gpg-mailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 paragonie/gpg-mailer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
DUKPT implementation in PHP
Creates new sare mail transport for laravel applications
A library for reading KeePass 2.x databases
Laravel authentication middleware for UZI passes.
A fast and dynamic Merkle tree implementation
A shared set of open-source enums for frequently used domains, helping reduce duplication and improve consistency across software projects.
统计信息
- 总下载量: 24.91k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 95
- 点击次数: 22
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-05