Skip to main content

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)"

Code and documentation copyright 2021 shabbywu(shabbywu@qq.com).
Code released under the Apache 2.0 license.

Reference

Metadata

Release files for py-libtrust 2.1.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 py-libtrust 2.1.1
File Size Uploaded
py_libtrust-2.1.1.tar.gz 13.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-libtrust 2.1.1
File Interpreter ABI Platform
py_libtrust-2.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 29.7 kB

Release files / py_libtrust-2.1.1.tar.gz

Download URL py_libtrust-2.1.1.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b1e29f332965a2fe095e9a650b595d88ec53171f32e8a1f9dd3b5c9fbce083e5
BLAKE2b-256 checksum
How to use checksums
1314d40bc16e7c88ca9b56ae0b1c061bb81289c7a4158967e1432115e5836b31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release files / py_libtrust-2.1.1-py3-none-any.whl

Download URL py_libtrust-2.1.1-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4aa27e068fb3feb01bf344829a6d066ba74788d09146f761872506737f362624
BLAKE2b-256 checksum
How to use checksums
674de27323e9e2dee4596803f1ea06161e3a1324dc17f18dbc44da99fa23bcd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release history Release notifications | RSS feed

This release

2.1.1 This release

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

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