Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paragonie/gpg-mailer
GnuPG-encrypted emails made easy
https://github.com/paragonie/gpg-mailer
emails encrypted encrypted-email gnupg gpg-mailer mailer php signed zend-framework
Last synced: 3 months ago
JSON representation
GnuPG-encrypted emails made easy
- Host: GitHub
- URL: https://github.com/paragonie/gpg-mailer
- Owner: paragonie
- License: mit
- Created: 2016-06-04T22:55:26.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-01-28T23:05:45.000Z (almost 3 years ago)
- Last Synced: 2024-07-19T03:49:13.066Z (4 months ago)
- Topics: emails, encrypted, encrypted-email, gnupg, gpg-mailer, mailer, php, signed, zend-framework
- Language: PHP
- Homepage:
- Size: 55.7 KB
- Stars: 96
- Watchers: 12
- Forks: 18
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GPG-Mailer
[![Build Status](https://travis-ci.org/paragonie/gpg-mailer.svg?branch=master)](https://travis-ci.org/paragonie/gpg-mailer)
[![Latest Stable Version](https://poser.pugx.org/paragonie/gpg-mailer/v/stable)](https://packagist.org/packages/paragonie/gpg-mailer)
[![Latest Unstable Version](https://poser.pugx.org/paragonie/gpg-mailer/v/unstable)](https://packagist.org/packages/paragonie/gpg-mailer)
[![License](https://poser.pugx.org/paragonie/gpg-mailer/license)](https://packagist.org/packages/paragonie/gpg-mailer)
[![Downloads](https://img.shields.io/packagist/dt/paragonie/gpg-mailer.svg)](https://packagist.org/packages/paragonie/gpg-mailer)Send GPG-encrypted emails (using [zend-mail](https://github.com/zendframework/zend-mail)
and [Crypt_GPG](https://github.com/pear/Crypt_GPG)).License: MIT
## The GPG-Mailer API in a Nutshell
```php
/**
* 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
addTo('[email protected]', '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 (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
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
addTo('[email protected]', '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 (fingerprint):
$fingerprint = '7F52D5C61D1255C731362E826B97A1C2826404DA';// Finally:
$gpgMailer->send($message, $fingerprint);
```Alternatively, we could define our constructor as above but then use
`setPrivateKey()` like so:```php
$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
addTo('[email protected]', '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](https://paragonie.com/enterprise).