{"id":13828270,"url":"https://github.com/paragonie/gpg-mailer","last_synced_at":"2025-04-09T18:17:27.985Z","repository":{"id":44716441,"uuid":"60433766","full_name":"paragonie/gpg-mailer","owner":"paragonie","description":"GnuPG-encrypted emails made easy","archived":false,"fork":false,"pushed_at":"2022-01-28T23:05:45.000Z","size":57,"stargazers_count":95,"open_issues_count":3,"forks_count":16,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-09T18:17:24.241Z","etag":null,"topics":["emails","encrypted","encrypted-email","gnupg","gpg-mailer","mailer","php","signed","zend-framework"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paragonie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-04T22:55:26.000Z","updated_at":"2025-03-24T01:10:35.000Z","dependencies_parsed_at":"2022-08-24T14:11:11.718Z","dependency_job_id":null,"html_url":"https://github.com/paragonie/gpg-mailer","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fgpg-mailer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fgpg-mailer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fgpg-mailer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paragonie%2Fgpg-mailer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paragonie","download_url":"https://codeload.github.com/paragonie/gpg-mailer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085321,"owners_count":21045139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["emails","encrypted","encrypted-email","gnupg","gpg-mailer","mailer","php","signed","zend-framework"],"created_at":"2024-08-04T09:02:39.215Z","updated_at":"2025-04-09T18:17:27.964Z","avatar_url":"https://github.com/paragonie.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# GPG-Mailer\n\n[![Build Status](https://travis-ci.org/paragonie/gpg-mailer.svg?branch=master)](https://travis-ci.org/paragonie/gpg-mailer)\n[![Latest Stable Version](https://poser.pugx.org/paragonie/gpg-mailer/v/stable)](https://packagist.org/packages/paragonie/gpg-mailer)\n[![Latest Unstable Version](https://poser.pugx.org/paragonie/gpg-mailer/v/unstable)](https://packagist.org/packages/paragonie/gpg-mailer)\n[![License](https://poser.pugx.org/paragonie/gpg-mailer/license)](https://packagist.org/packages/paragonie/gpg-mailer)\n[![Downloads](https://img.shields.io/packagist/dt/paragonie/gpg-mailer.svg)](https://packagist.org/packages/paragonie/gpg-mailer)\n\nSend GPG-encrypted emails (using [zend-mail](https://github.com/zendframework/zend-mail)\nand [Crypt_GPG](https://github.com/pear/Crypt_GPG)).\n\nLicense: MIT\n\n## The GPG-Mailer API in a Nutshell\n\n```php\n/**\n * Import a public key, return the fingerprint\n *\n * @param string $gpgKey An ASCII armored public key\n * @return string The GPG fingerprint for this key\n */\npublic function import(string $gpgKey): string;\n\n/**\n * Get the public key corresponding to a fingerprint.\n *\n * @param string $fingerprint\n * @return string\n */\npublic function export(string $fingerprint): string;\n\n/**\n * Encrypt then email a message\n *\n * @param Message $message    The message data\n * @param string $fingerprint Which public key fingerprint to use\n */\npublic function send(Message $message, string $fingerprint);\n\n/**\n * Email a message without encrypting it.\n *\n * @param Message $message The message data\n * @param bool $force      Send even if we don't have a private key?\n */\npublic function sendUnencrypted(Message $message, bool $force = false);\n```\n\n## Example: Encrypt Outbound Emails with Your GnuPG Public Key\n\n```php\n\u003c?php\nuse \\ParagonIE\\GPGMailer\\GPGMailer;\nuse \\Zend\\Mail\\Message;\nuse \\Zend\\Mail\\Transport\\Sendmail;\n\n// First, create a Zend\\Mail message as usual:\n$message = new Message;\n$message-\u003eaddTo('test@example.com', 'Test Email');\n$message-\u003esetBody('Cleartext for now. Do not worry; this gets encrypted.');\n\n// Instantiate GPGMailer:\n$gpgMailer = new GPGMailer(\n    new Sendmail(), \n    ['homedir' =\u003e '/homedir/containing/keyring']\n);\n\n// GPG public key for \u003csecurity@paragonie.com\u003e (fingerprint):\n$fingerprint = '7F52D5C61D1255C731362E826B97A1C2826404DA';\n\n// Finally:\n$gpgMailer-\u003esend($message, $fingerprint); \n```\n\nIf you're encrypting with a user provided public key (and they didn't tell you\ntheir fingerprint), do this instead:\n\n```php\n\u003c?php\n\n/**\n * Output from: gpg --armor --export user@example.com\n *\n * This is our security team's GPG public key. You probably don't\n * want to use ours, as only we can decrypt the messages.\n *\n * @var string \n */\n$ASCIIArmoredPublicKey = \"-----BEGIN PGP PUBLIC KEY BLOCK-----\nVersion: SKS 1.1.5\n\nmQENBFUgwRUBCADcIpqNwyYc5UmY/tpx1sF/rQ3knR1YNXYZThzFV+Gmqhp1fDH5qBs9foh1\nxwI6O7knWmQngnf/nBumI3x6xj7PuOdEZUh2FwCG/VWnglW8rKmoHzHAivjiu9SLnPIPAgHS\nHeh2XD7q3Ndm3nenbjAiRFNl2iXcwA2cTQp9Mmfw9vVcw0G0z1o0G3s8cC8ZS6flFySIervv\nfSRWj7A1acI5eE3+AH/qXJRdEJ+9J8OB65p1JMfk6+fWgOB1XZxMpz70S0rW6IX38WDSRhEK\n2fXyZJAJjyt+YGuzjZySNSoQR/V6vNYnsyrNPCJ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RQZFApdkBiIVpXgQzzRl6mxX05WkWZHjlQigatjUUQWQtOBTCa+9pFGHopTqA12ju\nrLqrQyYMlSfQCyXtc1fQGvedXhTVnBYQ6DXH6hE+uFDj5/iT4WUVCm8ngfnhqH38NoB+RNn2\nF3EBq5RMx0NF5Kzx3XkZvWvNgFXlSlxkDE7GUpLa6me5AQ0EVSDBFQEIALNkpzSuJsHAHh79\nsc0AYWztdUe2MzyofQbbOnOCpWZebYsC3EXU335fIg59k0m6f+O7GmEZzzIv5v0i99GS1R8C\nJm6FvhGqtH8ZqmOGbc71WdJSiNVE0kpQoJlVzRbig6ZyyjzrggbM1eh5OXOk5pw4+23FFEdw\n7JWU0HJS2o71r1hwp05Zvy21kcUEobz/WWQQyGS0Neo7PJn+9KS6wOxXul/UE0jct/5f7KLM\ndWMJ1VgniQmmhjvkHLPSICteqCI04RfcmMseW9gueHQXeUu1SNIvsWa2MhxjeBej3pDnrZWs\nzKwygF45GO9/v4tkIXNMy5J1AtOyRgQ3IUMqp8EAEQEAAYkBHwQYAQIACQUCVSDBFQIbDAAK\nCRBrl6HCgmQE2jnIB/4/xFz8InpM7eybnBOAir3uGcYfs3DOmaKn7qWVtGzvrKpQPYnVtlU2\ni6Z5UO4c4jDLT/8Xm1UDz3Lxvqt4xCaDwJvBZexU5BMK8l5DvOzH6o6P2L1UDu6BvmPXpVZz\n7/qUhOnyf8VQg/dAtYF4/ax19giNUpI5j5o5mX5w80RxqSXV9NdSL4fdjeG1g/xXv2luhoV5\n3T1bsycI3wjk/x5tV+M2KVhZBvvuOm/zhJjeoLWp0saaESkGXIXqurj6gZoujJvSvzl0n9F9\nVwqMEizDUfrXgtD1siQGhP0sVC6qha+F/SAEJ0jEquM4TfKWWU2S5V5vgPPpIQSYRnhQW4b1\n=Z4m0\n-----END PGP PUBLIC KEY BLOCK-----\";\n\n// Then to import.\n$fingerprint = $gpgMailer-\u003eimport($ASCIIArmoredPublicKey);\n```\n\n## Sign Emails with the Server's Private Key \n\n### Signed and Encrypted\n\nTo add signing, we pass the signing key to the third argument of the\nGPGMailer constructor.\n\n```php\n\u003c?php\n\nuse \\ParagonIE\\GPGMailer\\GPGMailer;\nuse \\Zend\\Mail\\Message;\nuse \\Zend\\Mail\\Transport\\Sendmail;\n\n// First, create a Zend\\Mail message as usual:\n$message = new Message;\n$message-\u003eaddTo('test@example.com', 'Test Email');\n$message-\u003esetBody('Cleartext for now. Do not worry; this gets encrypted.');\n\n$signingKey = file_get_contents('tests/private.key');\n\n// Instantiate GPGMailer:\n$gpgMailer = new GPGMailer(\n    new Sendmail(), \n    ['homedir' =\u003e '/homedir/containing/keyring'],\n    $signingKey\n);\n\n// GPG public key for \u003csecurity@paragonie.com\u003e (fingerprint):\n$fingerprint = '7F52D5C61D1255C731362E826B97A1C2826404DA';\n\n// Finally:\n$gpgMailer-\u003esend($message, $fingerprint); \n```\n\nAlternatively, we could define our constructor as above but then use\n`setPrivateKey()` like so:\n\n```php\n$gpgMailer = new GPGMailer(\n    new Sendmail(), \n    ['homedir' =\u003e '/homedir/containing/keyring']\n);\n\n$signingKey = file_get_contents('tests/private.key');\n$gpgMailer-\u003esetPrivateKey($signingKey);\n```\n\n### Signed, But Not Encrypted\n\nSame as above, except we don't need to load the recipient's fingerprint\nand we use the `sendUnencrypted()` method instead.\n\n```php\n\u003c?php\nuse \\ParagonIE\\GPGMailer\\GPGMailer;\nuse \\Zend\\Mail\\Message;\nuse \\Zend\\Mail\\Transport\\Sendmail;\n\n// First, create a Zend\\Mail message as usual:\n$message = new Message;\n$message-\u003eaddTo('test@example.com', 'Test Email');\n$message-\u003esetBody('Cleartext for now. Do not worry; this gets encrypted.');\n\n$signingKey = file_get_contents('tests/private.key');\n\n$gpgMailer = new GPGMailer(\n    new Sendmail(), \n    ['homedir' =\u003e '/homedir/containing/keyring'],\n    $signingKey\n);\n\n$gpgMailer-\u003esendUnencrypted($message); \n```\n\n## Support Contracts\n\nIf your company uses this library in their products or services, you may be\ninterested in [purchasing a support contract from Paragon Initiative Enterprises](https://paragonie.com/enterprise).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparagonie%2Fgpg-mailer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparagonie%2Fgpg-mailer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparagonie%2Fgpg-mailer/lists"}