Yet another docker/libtrust implement by python.
Project description
py-libtrust - Yet another docker/libtrust implement by python.
Libtrust is library for managing authentication and authorization using public key cryptography.
Works for Python 3.6+.
Usage
Install
You can install from PyPi.
❯ pip install py-libtrust
Example
Sign/Verify a jose-json-web-signature
import datetime
from libtrust.keys.ec_key import generate_private_key
from libtrust.jsonsign import JSONSignature
# Generate a EC P256 private key
ec_key = generate_private_key("P-256")
your_content = {
"author": "shabbywu(shabbywu@qq.com)"
}
# New a JSONSignature
js = JSONSignature.new(your_content)
# signature
js.sign(ec_key, dt=datetime.datetime.utcfromtimestamp(0))
jws = js.to_jws()
loaded_js = JSONSignature.from_jws(jws)
assert js == loaded_js
assert js.verify() == loaded_js.verify()
Serialize/Deserialize a self-signed JSON signature
import json
import datetime
from libtrust.keys.ec_key import generate_private_key
from libtrust.jsonsign import JSONSignature
# Generate a EC P256 private key
ec_key = generate_private_key("P-256")
your_content = {
"author": "shabbywu(shabbywu@qq.com)"
}
# New a JSONSignature
js = JSONSignature.new(your_content)
# signature
js.sign(ec_key, dt=datetime.datetime.utcfromtimestamp(0))
pretty_signature = js.to_pretty_signature("signatures")
loaded_js = js.from_pretty_signature(pretty_signature)
assert js.verify() == loaded_js.verify()
assert json.loads(pretty_signature)["author"] == "shabbywu(shabbywu@qq.com)"
Copyright and license
Code and documentation copyright 2021 shabbywu(shabbywu@qq.com).
Code released under the Apache 2.0 license.
Reference
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
py-libtrust-1.0.3.tar.gz
(13.8 kB
view hashes)
Built Distribution
Close
Hashes for py_libtrust-1.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1d7f33323760f782c25f614fc14a952700f6c124f9686a40030e7cd1660315d |
|
MD5 | 52637f431c77b2f9905e84c42a4cb66f |
|
BLAKE2b-256 | 7ac3b25d98ae4688721fc2c74956197ab78589a54e88996060a262674d494f61 |