Skip to main content

A shared library for SDC services that use JWT with JWE

Project description

sdc-cryptography

Build Status Codacy Badge codecov A common source code library for SDC services that use JWE. Apps wishing to use this should add the sdc_cryptography dependency to their requirements.txt and install with pip.

Basic Use (with pipenv, recommended)

Install requirements

pip install pipenv
make build

Run the unit tests

pipenv run make test

Create a package for deployment

pipenv run make sdist

Basic Use (with activated virtual environment)

Install requirements

These commands will generate a requirements file that pip can use. It doesn't have to be created this way but this is the easiest way.

pip install pipenv
pipenv lock -r --dev > requirements.txt
pip install -r requirements.txt

Run the unit tests

make test

Create a package for deployment

make sdist

Usage

Need to generate a keys.yml file first. Note, this requires a file system to store the file. Then it needs to be loaded, and a key store generated.

generate_keys.py <key_folder_location>

After this has been configured, encrypting and decrypting can be done as in the example below.

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 when a tag is created in Github. The configuration for this is in the .travis.yml file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sdc-cryptography-1.1.3.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sdc_cryptography-1.1.3-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file sdc-cryptography-1.1.3.tar.gz.

File metadata

  • Download URL: sdc-cryptography-1.1.3.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for sdc-cryptography-1.1.3.tar.gz
Algorithm Hash digest
SHA256 d051f3d6be960a068eca60783a0295b73a48bc96155f25421de73e01edfd6bbf
MD5 5034aa889d981ad36a70e49e11dd49f6
BLAKE2b-256 92532aaf508ccf569c272e6d04219d97e2149274de9893a77b445b6973679774

See more details on using hashes here.

File details

Details for the file sdc_cryptography-1.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for sdc_cryptography-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 814710af9259ccad78e7d4e7447500ee6ed9c131883f3494ad1276705f70526e
MD5 407258a689b44d8bafba57d7fe9e2631
BLAKE2b-256 fe1b35deba9d8b422214191fd59a066d861c0e0f72b5c94cc74d6aae39bbfdd6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page