Platform-Agnostic Security Tokens for Python
pip install python-pasetopython-mpasetolibsodium is required, this will check if it is installed on your system. On Ubuntu 20.04 you can get it with sudo apt install libsodium23.
Implements PASETO Version2 and Version4 protocols supporting v2.public, v2.local, v4.public and v4.local messages.
Every protocol version provides access to encrypt() / decrypt() and sign() / verify() functions.
Low level API is focuses on solid, high quality, production ready primitives as specified directly in the PASETO protocol. See paseto-spec for protocol details.
frompaseto.protocol.version2importencrypt, decryptmessage=b"foo"# your datakey=b"0"*32# encryption keytoken=encrypt(message, key)
plain_text=decrypt(token, key)
assertplain_text==messageprint(f"token={token}")
print(f"plain_text={plain_text}")
print(f"message={message}")frompaseto.protocol.version2importencrypt, decryptmessage=b"foo"# your datakey=b"0"*32# encryption keyoptional_footer=b"sample_footer"# authenticated but not encrypted metadatatoken=encrypt(message, key, optional_footer)
plain_text=decrypt(token, key, optional_footer)
assertplain_text==messageprint(f"token={token}")
print(f"plain_text={plain_text}")
print(f"message={message}")frompaseto.protocol.version4importcreate_symmetric_key, decrypt, encryptmessage=b"this is a secret message"# your datakey=create_symmetric_key() # encryption keytoken=encrypt(message, key)
plain_text=decrypt(token, key)
assertplain_text==messageprint(f"token={token}")
print(f"plain_text={plain_text}")
print(f"message={message}")frompaseto.protocol.version4importcreate_asymmetric_key, sign, verifymessage=b"this is a public message"# your datapublic_key, secret_key=create_asymmetric_key() # signing / verifying keystoken=sign(message, secret_key)
verified_message=verify(token, public_key)
assertverified_message==messageprint(f"token={token}")
print(f"verified_message={verified_message}")
print(f"message={message}")In the future a high level API will provide developer friendly access to low level API and support easy integration into other projects.
Typical dev workflow operations are automated in Makefile, including testing, linting, code quality checks, benchmarks and dev environment setup.
This library is under active development and maintenance. For any feedback, questions, comments or if you would like to request a feature, please raise an issue!