a Python implementation of TripleSec
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file TripleSec-0.5.1.tar.gz
.
File metadata
- Download URL: TripleSec-0.5.1.tar.gz
- Upload date:
- Size: 10.8 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9547a5cb433a96b429eadb36dc20f5f8af67b075d40652be475e16aba8b194c |
|
MD5 | 91dab930219419185e468b88a2656d47 |
|
BLAKE2b-256 | 760c3a5f8248a8be2b1ee8eb8aacb39acc77cfeb5644a0dd1f274916a19fbf3f |
File details
Details for the file TripleSec-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: TripleSec-0.5.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | aab678dcba57a5d62c00ed29f40e4f32258783153810b12183b428c74c78c7c7 |
|
MD5 | b49da26407410816567ca00fe1887dfe |
|
BLAKE2b-256 | a4b6b25c0481b8dc822f9067610cd5427aba4699939df94af507107be21fd7ca |