Skip to main content

python-triplesec

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

Metadata

Release files for TripleSec 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for TripleSec 0.5.1
File Size Uploaded
TripleSec-0.5.1.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for TripleSec 0.5.1
File Interpreter ABI Platform
TripleSec-0.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 23.4 kB

Release files / TripleSec-0.5.1.tar.gz

Download URL TripleSec-0.5.1.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b9547a5cb433a96b429eadb36dc20f5f8af67b075d40652be475e16aba8b194c
BLAKE2b-256 checksum
How to use checksums
760c3a5f8248a8be2b1ee8eb8aacb39acc77cfeb5644a0dd1f274916a19fbf3f
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / TripleSec-0.5.1-py3-none-any.whl

Download URL TripleSec-0.5.1-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aab678dcba57a5d62c00ed29f40e4f32258783153810b12183b428c74c78c7c7
BLAKE2b-256 checksum
How to use checksums
a4b6b25c0481b8dc822f9067610cd5427aba4699939df94af507107be21fd7ca
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.5.1 This release

2 release files

0.5

3 release files

0.4

2 release files

0.3

1 release file

0.2

1 release file

0.1dev

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page