Skip to main content

A Python implementation of OpenPGP

Project description

https://travis-ci.org/SkierPGP/python-pgp.svg?branch=master https://coveralls.io/repos/SkierPGP/python-pgp/badge.png

Summary

python-pgp aims to reproduce the full functionality of GnuPG in Python. It may also be used for creating raw OpenPGP packets and packet streams for test purposes. This may be a bit of a heavyweight solution for some purposes.

This is a fork of the original library - the original one does not seem to be active and/or have a PyPI package.

Alternatives

Other Python packages which provide related functionality:

  • pyassuan - communicate with GnuPG using its socket protocol.

  • pgpdump - a pure python library for parsing OpenPGP packets.

  • gnupg - a wrapper around the GnuPG executable.

  • python-gnupg - another wrapper around the GnuPG executable.

  • gpgkeys - another wrapper around the GnuPG executable.

  • gpglib - a pure python library for parsing OpenPGP packets and decrypting messages.

  • OpenPGP - an unmaintained pure python library with much of the functionality of old versions of GnuPG.

  • encryptedfile - a pure python library for symmetrically encrypting files in an OpenPGP-compatible way.

  • PGPy - a pure python library with basic parsing and signing of OpenPGP packets.

  • OpenPGP-Python - a pure python port of openpgp-php. It can parse OpenPGP packets and verify & create signatures.

System requirements

  • build-essential

For Twofish support

  • libtwofish-dev

Installation

pip install pgp

with Twofish support:

pip install pgp[twofish]

with Camellia support:

pip install pgp[camellia]

with Twofish & Camellia support:

pip install pgp[camellia,twofish]

Usage

High level

Parsing a message

from pgp import read_message
message = read_message(data)

Parsing a transferrable key

from pgp import read_key
key = read_key(data)

Loading the GnuPG database

from pgp import get_gnupg_db
db = get_gnupg_db()
key = db.search(user_id='Joe')[0]

Retrieving a key from a keyserver and creating a message for it

>>> import datetime
>>> from pgp import *
>>> from pgp.keyserver import get_keyserver
>>> ks = get_keyserver('hkp://pgp.mit.edu/')
>>> results = ks.search('Joe Bloggs')
>>> recipient_key = results[0].get()
>>> message = message.TextMessage(
...     u"This message was encrypted using Python PGP",
...     datetime.datetime.now())
>>> my_secret_key = read_key_file('secret_key.gpg')
>>> my_secret_key.unlock('My passphrase')
>>> message = message.sign(my_secret_key)
>>> message = message.compress(2)  # Compression algorithm 2
>>> message = message.public_key_encrypt(9, recipient_key)
>>> message_packets = message.to_packets()
>>> message_data = b''.join(map(bytes, message_packets))
>>> armored_message = armor.ASCIIArmor(
...     armor.PGP_MESSAGE, message_data)
>>> file_handle = open('message.asc', 'w')
>>> file_handle.write(str(armored_message))
>>> file_handle.close()

Low level

Parsing a packet stream

from pgp.packets import parsers
parsers.parse_binary_packet_data(packet_data)

Serializing a packet

from pgp.packets import parsers
packets = parsers.parse_binary_packet_data(packet_data)
b''.join(map(bytes, packets))

Security

If you are using this package to handle private key data and decryption, please note that there is no (reasonable) way currently in Python to securely erase memory and that copies of things are made often and in non-obvious ways. If you are concerned about key data being compromised by a memory leak, do not use this package for handling secret key data. On the other hand, “if your memory is constantly being compromised, I would re-think your security setup.”

OpenPGP uses compression algorithms. Beware when feeding untrusted data into this library of Zip bomb or similar denial of service attacks.

Development

The main repository for this package is on GitHub. To develop on the package and install development dependencies, clone the repository and install the ‘dev’ extras.:

git clone git@github.com:mitchellrj/python-pgp.git
cd python-pgp
virtualenv .
bin/pip install -e ".[dev]"

Running tests

bin/python setup.py nosetests

Building documentation

bin/python setup.py build_sphinx

License

Copyright (C) 2014 Richard Mitchell

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-pgp-0.0.1.tar.gz (126.0 kB view details)

Uploaded Source

Built Distributions

py_pgp-0.0.1-py3.4.egg (375.8 kB view details)

Uploaded Source

py_pgp-0.0.1-py3.3.egg (381.9 kB view details)

Uploaded Source

py_pgp-0.0.1-py3.2.egg (295.3 kB view details)

Uploaded Source

py_pgp-0.0.1-py3-none-any.whl (172.9 kB view details)

Uploaded Python 3

File details

Details for the file py-pgp-0.0.1.tar.gz.

File metadata

  • Download URL: py-pgp-0.0.1.tar.gz
  • Upload date:
  • Size: 126.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py-pgp-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cad3611491598d1111a8abe0ebe5aa55119353bd8f7c78f623c16d131d3b85fc
MD5 3a20198672730d10fd35bd18047023a6
BLAKE2b-256 63d142ae81ae33db41b7474df650c71ea7648a14477a8103d53c974c872a24b8

See more details on using hashes here.

File details

Details for the file py_pgp-0.0.1-py3.4.egg.

File metadata

  • Download URL: py_pgp-0.0.1-py3.4.egg
  • Upload date:
  • Size: 375.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py_pgp-0.0.1-py3.4.egg
Algorithm Hash digest
SHA256 1c683e4cbae84f4f5500714493bbdb2845238bd4860e61cb5485b7a1094fd14f
MD5 b02ced06a077a8d539a73503021d4f44
BLAKE2b-256 66ad8da6e200632a3232ae59f0ef7bd24a611263fb20cc6028f31923158b10ca

See more details on using hashes here.

File details

Details for the file py_pgp-0.0.1-py3.3.egg.

File metadata

  • Download URL: py_pgp-0.0.1-py3.3.egg
  • Upload date:
  • Size: 381.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py_pgp-0.0.1-py3.3.egg
Algorithm Hash digest
SHA256 ed96b27acf35ff69c8902364594429eb0d83e95bec5157b544fc21630af4d5eb
MD5 b4b77fb556072eb94d652b719b2c50b4
BLAKE2b-256 b28847f5a918c196f2b956c22d493f6f1ca1827d8f3ecd81d602139045f99aa7

See more details on using hashes here.

File details

Details for the file py_pgp-0.0.1-py3.2.egg.

File metadata

  • Download URL: py_pgp-0.0.1-py3.2.egg
  • Upload date:
  • Size: 295.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py_pgp-0.0.1-py3.2.egg
Algorithm Hash digest
SHA256 3bf921781fdef4b8a9bc83cf2a76782cbd3446b4c96e4f4d2edb81821b8bad4d
MD5 38037cacb2660a9ff7683043c84b8cd4
BLAKE2b-256 3abbc77504dfa1847310182f3c165ef08256c1819a1325040ef2fffd6ad1ba70

See more details on using hashes here.

File details

Details for the file py_pgp-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for py_pgp-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e3d2b7bdf73d8e97cca12abad484df4d14d6b08da206f9547b839ff702a4ff83
MD5 dd7242bccdb855db099e077940d67f47
BLAKE2b-256 473a13a9d55dabdb316d82017014553e97ebc11e833c07615a5b24930acf01ae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page