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: 7 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 9 years ago)
- Default Branch: master
- Last Pushed: 2022-01-28T23:05:45.000Z (almost 4 years ago)
- Last Synced: 2025-04-09T18:17:24.241Z (7 months ago)
- Topics: emails, encrypted, encrypted-email, gnupg, gpg-mailer, mailer, php, signed, zend-framework
- Language: PHP
- Homepage:
- Size: 55.7 KB
- Stars: 95
- Watchers: 11
- Forks: 16
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GPG-Mailer
[](https://travis-ci.org/paragonie/gpg-mailer)
[](https://packagist.org/packages/paragonie/gpg-mailer)
[](https://packagist.org/packages/paragonie/gpg-mailer)
[](https://packagist.org/packages/paragonie/gpg-mailer)
[](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('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 (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('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 (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('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](https://paragonie.com/enterprise).