sdc-cryptography
A common source code library for SDC services that use JWE. Apps wishing to use this should add the sdc-cryptography dependency to their project.
Usage
Before using the library, you need to generate a keys.yml file. The key_folder_location should contain the public and private keys that are required by the SDC service using the library. To generate the keys.yml run:
generate_keys.py <key_folder_location>
After this has been configured, encrypting and decrypting can be done as follows:
secrets_from_file = yaml.safe_load("keys.yml")
validate_required_secrets(secrets_from_file, EXPECTED_SECRETS, KEY_PURPOSE_SUBMISSION)
key_store = KeyStore(secrets_from_file)
# Encrypt JSON (Purpose has a single encryption key in the key store)
from sdc.crypto.encrypter import encrypt
encrypted_json = encrypt(json, key_store, key_purpose)
# Encrypt JSON with encryption service (Purpose has multiple encryption keys in the key store each tagged with a service)
from sdc.crypto.encrypter import encrypt
encrypted_json = encrypt(json, key_store, key_purpose, encryption_for_service="some-service")
# Decrypt UTF8 jwe token
from sdc.crypto.decrypter import decrypt
data_bytes = data.decode('UTF8')
decrypted_json = decrypt(data_bytes, key_store, key_purpose)
PyPi
This repo is available from PyPi at sdc-cryptography
The package is published automatically to PyPi via a GitHub Action when a release tag is created in GitHub. The configuration for this is in the .github/workflows/release.yaml file.
Developing changes
This repository uses poetry. Ensure you have it installed.
To install the dependencies run:
make install
Run linting and the unit tests:
make test
Create a package for deployment:
make build
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sdc_cryptography-1.4.0.tar.gz.
File metadata
- Download URL: sdc_cryptography-1.4.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d331477e3de3336d5cc5a3e4b7bc282eeae20a9c74fb77321b5da8371493e75
|
|
| MD5 |
630408b0adee36f7db93f89aebe678b4
|
|
| BLAKE2b-256 |
079069a365df212c8e43fccd01a097ec52dedce6c60db6bd81d00fc2c65db047
|
File details
Details for the file sdc_cryptography-1.4.0-py3-none-any.whl.
File metadata
- Download URL: sdc_cryptography-1.4.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bf97d06888fd4e3e5daf5b40ca15234eb085cccf201c5114ba1584e6b078076
|
|
| MD5 |
8ac83d14942cdd157d26cce6534b560e
|
|
| BLAKE2b-256 |
1075972d8e37af1ecee33274f6f070cf156194c76514dd1b97e4355e83bad6c1
|