Skip to main content

symmetric key encryption and decryption compatible with GPG

Project description

tinygpgs is a fast module and standalone Python 2 script for doing symmetric key (passphrase-based) encryption and decryption using the OpenPGP file format compatible with GPG (GnuPG).

Usage

File class API usage for encryption:

import getpass
from tinygpgs.file import GpgSymmetricFile
f = GpgSymmetricFile('FILE.bin.gpg', 'wb', getpass.getpass())
try:
  f.write('Hello, World!\n')
  f.write('This is the end.\n')
finally:
  f.close()

File class API usage for decryption:

import getpass
from tinygpgs.file import GpgSymmetricFile
f = GpgSymmetricFile('FILE.bin', 'rb', getpass.getpass())
try:
  # Use f.read(8192) in a loop instead to limit memory usage.
  print(f.read())
finally:
  f.close()

For encryption, it also provides the encryptedfile 1.1.1 interface for easy migration:

import getpass
from tinygpgs.file import EncryptedFile  # Just for compatibility.
f = EncryptedFile('FILE.bin.gpg', mode='wb', passphrase=getpass.getpass())
try:
  f.write('Hello, World!\n')
  f.write('This is the end.\n')
finally:
  f.close()

Command-line tool usage:

$ python -m tinygpgs -c FILE.bin                  # Encrypt.
Enter passphrase:
$ python -m tinygpgs -d <FILE.bin.gpg >FILE2.bin  # Decrypt.
Enter passphrase:
$ cmp FILE.bin FILE2.bin

The command-line tool has many flags identical to gpg(1), so you can use python -m tinygpgs as a drop-in replacement for gpg for symmetric key encryption and decryption.

Features

tinygpgs supports all ciphers, hashes, string-to-key modes, output formats (binary and ASCII armor) and compression methods in the OpenPGP RFC for both encryption and decryption. All these settings are configurable in keyword arguments to the class constructors and in command-line flags.

tinygpgs doesn’t support public-key cryptography (e.g. encryption, signing and key generation).

Installation

To get the module, run this:

$ python -m pip install tinygpgs pycrypto

Please note that tinygpgs works without pycrypto as well, but with pycrypto it works much faster, even comparable with gpg(1): less than 1.37 slower.

To get the standalone version of the command-line tool (single executable file for Unix, contains the module embedded), see https://github.com/pts/tinygpgs.

You need Python >=2.4 to use tinygpgs as a script or a module. It was tested with 2.4 and 3.8, and all the major versions in-between.

More info

See see https://github.com/pts/tinygpgs.

License

tinygpgs is free software released under the MIT license. There is NO WARRANTY. Use at your risk.

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

tinygpgs-0.18.tar.gz (76.8 kB view details)

Uploaded Source

File details

Details for the file tinygpgs-0.18.tar.gz.

File metadata

  • Download URL: tinygpgs-0.18.tar.gz
  • Upload date:
  • Size: 76.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/2.7.13

File hashes

Hashes for tinygpgs-0.18.tar.gz
Algorithm Hash digest
SHA256 326b94af47e9c2092434d1d1a6826a66501ba288289809a02199aea6760d6b51
MD5 0405877ade8fc272208c5efeab99ce8c
BLAKE2b-256 9cb6f76f5f241817fd2ee439f4a7268da27ba27326f17738ad578bc016ad578c

See more details on using hashes here.

Supported by

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