Skip to main content

a Python implementation of TripleSec

Project description

Build Status Coverage Status PyPi version PyPi downloads

A Python port of the TripleSec library. See also the JS implementation.

Compatible with Python 2.7 and 3.6+.

Installation

pip install TripleSec

Usage

Instantiate a triplesec.TripleSec(key=None) object, with or without a key (if omitted it will have to be specified at each use), then use the encrypt(message, key=None) and decrypt(ciphertext, key=None) methods.

All values must be binary strings (str on Python 2, bytes on Python 3)

Shortcuts

The (unkeyed) functions encrypt and decrypt are exposed at the module level.

Command line tool

TripleSec offers a triplesec command line tool to encrypt and decrypt messages from the terminal.

Here is the help:

Command-line TripleSec encryption-decryption tool

usage: triplesec [-h] [-b | --hex] [-k KEY] {enc|dec} [data]

positional arguments:
  {enc|dec}          enc: encrypt and sign a message with TripleSec; by
                     default output a hex encoded ciphertext (see -b and
                     --hex) -- dec: decrypt and verify a TripleSec ciphertext
  data               the TripleSec message or ciphertext; if not specified it
                     will be read from stdin; by default ciphertexts will be
                     considered hex encoded (see -b and --hex)

optional arguments:
  -h, --help         show this help message and exit
  -b, --binary       consider all input (key, plaintext, ciphertext) to be
                     plain binary data and output everything as binary data -
                     this turns off smart decoding/encoding - if you pipe
                     data, you should use this
  --hex              consider all input (key, plaintext, ciphertext) to be hex
                     encoded; hex encode all output
  -k KEY, --key KEY  the TripleSec key; if not specified will check the
                     TRIPLESEC_KEY env variable, then prompt the user for it
  --compatibility    Use Keccak instead of SHA3 for the second MAC and reverse
                     endianness of Salsa20 in version 1. Only effective in
                     versions before 4.

Changes in 0.5

For message authentication, the Triplesec spec uses the Keccak SHA3 proposal function for versions 1 through 3, but for some time, this library used the standardized SHA3-512 function instead. Thus, by default, the Python implementation for versions 1 through 3 is incompatible with the JavaScript and Golang implementations. From version 4 and going forward, the spec will use only the standardized SHA3-512 function (provided, for example, by hashlib in Python), and the Python, JavaScript, and Golang implementations will be compatible.

If you would like to use Keccak with versions 1 through 3 (and thus achieve compatibility with the Node and Go packages), you can pass in compatibility=True to encrypt and decrypt, or on the commandline as detailed in the above section.

Additionally, encryptions that do not specify a version will now use version 4 by default, which is not compatible with previous versions.

Example

>>> import triplesec
>>> x = triplesec.encrypt(b"IT'S A YELLOW SUBMARINE", b'* password *')
>>> print(triplesec.decrypt(x, b'* password *').decode())
IT'S A YELLOW SUBMARINE
>>> from triplesec import TripleSec
>>> T = TripleSec(b'* password *')
>>> x = T.encrypt(b"IT'S A YELLOW SUBMARINE")
>>> print(T.decrypt(x).decode())
IT'S A YELLOW SUBMARINE

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

TripleSec-0.5.tar.gz (10.7 kB view details)

Uploaded Source

Built Distributions

TripleSec-0.5-py3.7.egg (24.9 kB view details)

Uploaded Source

TripleSec-0.5-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file TripleSec-0.5.tar.gz.

File metadata

  • Download URL: TripleSec-0.5.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for TripleSec-0.5.tar.gz
Algorithm Hash digest
SHA256 e86a8524ec371a8a5198d3485c40e566ca87675dc19cdd7b11d4d2c11f8f1ff2
MD5 54d94681683b2c351910ac8bb5ccfa1a
BLAKE2b-256 2f1fd827312ed41ebb4da05ee17cccbadfa1750f19c2e926005eb490b2c4de37

See more details on using hashes here.

File details

Details for the file TripleSec-0.5-py3.7.egg.

File metadata

  • Download URL: TripleSec-0.5-py3.7.egg
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for TripleSec-0.5-py3.7.egg
Algorithm Hash digest
SHA256 75c091cf8de7c987349e0f24a46138a23c34a8690937ddbcc73ff398c3153d32
MD5 144c7207db495285599890f5b6abd8d7
BLAKE2b-256 ff1f80410eab3184b247948e6c0df011bdd3e5ce4d4d7d22aac11e86d93860c9

See more details on using hashes here.

File details

Details for the file TripleSec-0.5-py3-none-any.whl.

File metadata

  • Download URL: TripleSec-0.5-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for TripleSec-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ba8d96fa370ce94fd7078b9cddab2daf66b8a71eaf5ad7df9b0f5ab758ddb65b
MD5 6de2af7a0073156ad0933f82a25be6c3
BLAKE2b-256 9afe8c0956e5ff12f235a7849864d2b44bc5d8740a94f58d7440e24ed3672ad5

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