Skip to main content

Python library that provides a simple interface for symmetric (i.e., secret-key) and asymmetric (i.e., public-key) encryption/decryption primitives.

Project description

Python library that provides a simple interface for symmetric (i.e., secret-key) and asymmetric (i.e., public-key) encryption/decryption primitives.

PyPI version and link. Read the Docs documentation status. GitHub Actions status. Coveralls test coverage summary.

Purpose

This library provides simple and straightforward methods for symmetric (i.e., secret-key) and asymmetric (i.e., public-key) cryptographic encryption and decryption capabilities. The library’s interface is designed for ease of use and therefore hides from users some of the flexibilities and performance trade-offs that can be leveraged via direct use of the underlying cryptographic libraries.

The library’s name is a reference to boron trichloride, as it is a wrapper and binding for a limited set of capabilities found in libsodium. However, it can also be an acronym for basic cryptographic library.

Installation and Usage

This library is available as a package on PyPI:

python -m pip install bcl

The library can be imported in the usual ways:

import bcl
from bcl import *

Examples

This library provides concise methods for implementing symmetric encryption workflows:

>>> from bcl import symmetric
>>> s = symmetric.secret() # Generate a secret key.
>>> c = symmetric.encrypt(s, 'abc'.encode())
>>> symmetric.decrypt(s, c).decode('utf-8')
'abc'

Asymmetric encryption workflows are also supported:

>>> from bcl import asymmetric
>>> s = asymmetric.secret() # Generate a secret key.
>>> p = asymmetric.public(s) # Generate a corresponding public key.
>>> c = asymmetric.encrypt(p, 'abc'.encode())
>>> asymmetric.decrypt(s, c).decode('utf-8')
'abc'

This library also provides a number of classes for representing keys (secret and public), nonces, plaintexts, and ciphertexts. All methods expect and return instances of the appropriate classes:

>>> from bcl import secret, public, cipher
>>> s = asymmetric.secret()
>>> isinstance(s, secret)
True
>>> p = asymmetric.public(s)
>>> isinstance(p, public)
True
>>> c = symmetric.encrypt(s, 'abc'.encode())
>>> type(c)
<class 'bcl.bcl.cipher'>
>>> symmetric.decrypt(bytes(s), c)
Traceback (most recent call last):
  ...
TypeError: can only decrypt using a symmetric secret key
>>> symmetric.decrypt(s, bytes(c))
Traceback (most recent call last):
  ...
TypeError: can only decrypt a ciphertext

Furthermore, the above classes are derived from bytes, so all methods and other operators supported by bytes objects are supported:

>>> p.hex()
'0be9cece7fee92809908bd14666eab96b77deebb488c738445d842a6613b7b48'

In addition, Base64 conversion methods are included for all of the above classes to support concise encoding and decoding of objects:

>>> p.to_base64()
'C+nOzn/ukoCZCL0UZm6rlrd97rtIjHOERdhCpmE7e0g='
>>> b = 'C+nOzn/ukoCZCL0UZm6rlrd97rtIjHOERdhCpmE7e0g='
>>> type(public.from_base64(b))
<class 'bcl.bcl.public'>

Development, Build, and Manual Installation Instructions

All development and installation dependencies are managed using setuptools and are fully specified in setup.py. The extras_require parameter is used to specify optional requirements for various development tasks. This makes it possible to specify additional options (such as docs, lint, and so on) when performing installation using pip:

python -m pip install .[docs,lint]

Building from Source

The library can be built manually from source within Linux and macOS using the sequence of commands below:

python -m pip install .[build]
python setup.py bdist_wheel

Developing the library further in a local environment and/or building the library from source requires libsodium. The step python setup.py bdist_wheel in the above attempts to automatically locate a copy of the libsodium source archive src/bcl/libsodium.tar.gz. If the archive corresponding to the operating system is not found, the build process attempts to download it. To support building offline, it is necessary to first download the appropriate libsodium archive to its designated location:

wget -O src/bcl/libsodium.tar.gz https://github.com/jedisct1/libsodium/releases/download/1.0.18-RELEASE/libsodium-1.0.18.tar.gz

The process for building manually from source within a Windows environment is not currently documented, but an example of one sequence of steps can be found in the Windows job entry within the GitHub Actions workflow defined in the file .github/workflows/lint-test-cover-docs-build-upload.yml.

Preparation for Local Development

Before documentation can be generated or tests can be executed, it is necessary to run the build process and then to use the command below to move the compiled libsodium shared/dynamic library file into its designated location (so that the module file src/bcl/bcl.py is able to import it):

cp build/lib*/bcl/_sodium*.* src/bcl

Manual Installation

Once the package is built, it can be installed manually using the command below:

python -m pip install -f dist . --upgrade

Documentation

Once the libsodium shared library file is compiled and moved into its designated location (as described in the relevant subsection above), the documentation can be generated automatically from the source files using Sphinx:

python -m pip install .[docs]
cd docs
sphinx-apidoc -f -E --templatedir=_templates -o _source .. ../setup.py ../src/bcl/sodium_ffi.py && make html

Testing and Conventions

Before unit tests can be executed, it is first necessary to prepare for local development by compiling and moving into its designated location the libsodium shared library file (as described in the relevant subsection above).

All unit tests are executed and their coverage is measured when using pytest (see pyproject.toml for configuration details):

python -m pip install .[test]
python -m pytest

Alternatively, all unit tests are included in the module itself and can be executed using doctest:

python src/bcl/bcl.py -v

Style conventions are enforced using Pylint:

python -m pip install .[lint]
python -m pylint src/bcl

Contributions

In order to contribute to the source code, open an issue or submit a pull request on the GitHub page for this library.

Versioning

The version number format for this library and the changes to the library associated with version number increments conform with Semantic Versioning 2.0.0.

Publishing

This library can be published as a package on PyPI by a package maintainer. First, install the dependencies required for packaging and publishing:

python -m pip install .[publish]

Ensure that the correct version number appears in setup.py and in .github/workflows/lint-test-cover-docs-build-upload.yml, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an automation rule that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ?.?.? with the version number):

git tag ?.?.?
git push origin ?.?.?

Remove any old build/distribution files. Then, package the source into a distribution archive:

rm -rf build dist src/*.egg-info
python setup.py sdist

Next, navigate to the appropriate GitHub Actions run of the workflow defined in lint-test-cover-docs-build-upload.yml. Click on the workflow and scroll down to the Artifacts panel. Download the archive files to the dist directory. Unzip all the archive files so that only the *.whl files remain:

cd dist && for i in `ls *.zip`; do unzip $i; done && rm *.zip && cd ..

Finally, upload the package distribution archive to PyPI:

python -m twine upload dist/*

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

bcl-2.3.1.tar.gz (16.8 kB view details)

Uploaded Source

Built Distributions

bcl-2.3.1-cp310-abi3-win_amd64.whl (96.4 kB view details)

Uploaded CPython 3.10+ Windows x86-64

bcl-2.3.1-cp310-abi3-win32.whl (88.7 kB view details)

Uploaded CPython 3.10+ Windows x86

bcl-2.3.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (740.2 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ x86-64

bcl-2.3.1-cp310-abi3-macosx_10_10_universal2.whl (525.7 kB view details)

Uploaded CPython 3.10+ macOS 10.10+ universal2 (ARM64, x86-64)

bcl-2.3.1-cp39-abi3-win_amd64.whl (96.4 kB view details)

Uploaded CPython 3.9+ Windows x86-64

bcl-2.3.1-cp39-abi3-win32.whl (88.7 kB view details)

Uploaded CPython 3.9+ Windows x86

bcl-2.3.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (740.1 kB view details)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ x86-64

bcl-2.3.1-cp39-abi3-macosx_10_10_universal2.whl (525.7 kB view details)

Uploaded CPython 3.9+ macOS 10.10+ universal2 (ARM64, x86-64)

bcl-2.3.1-cp39-abi3-macosx_10_9_x86_64.whl (315.6 kB view details)

Uploaded CPython 3.9+ macOS 10.9+ x86-64

bcl-2.3.1-cp38-abi3-win_amd64.whl (96.4 kB view details)

Uploaded CPython 3.8+ Windows x86-64

bcl-2.3.1-cp38-abi3-win32.whl (88.7 kB view details)

Uploaded CPython 3.8+ Windows x86

bcl-2.3.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (740.4 kB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ x86-64

bcl-2.3.1-cp38-abi3-macosx_10_9_x86_64.whl (315.6 kB view details)

Uploaded CPython 3.8+ macOS 10.9+ x86-64

bcl-2.3.1-cp37-abi3-win_amd64.whl (96.4 kB view details)

Uploaded CPython 3.7+ Windows x86-64

bcl-2.3.1-cp37-abi3-win32.whl (88.7 kB view details)

Uploaded CPython 3.7+ Windows x86

bcl-2.3.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (740.1 kB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

bcl-2.3.1-cp37-abi3-macosx_10_9_x86_64.whl (315.6 kB view details)

Uploaded CPython 3.7+ macOS 10.9+ x86-64

File details

Details for the file bcl-2.3.1.tar.gz.

File metadata

  • Download URL: bcl-2.3.1.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for bcl-2.3.1.tar.gz
Algorithm Hash digest
SHA256 2a10f1e4fde1c146594fe835f29c9c9753a9f1c449617578c1473d6371da9853
MD5 177e47b2e449299be2e46cb1dac544c5
BLAKE2b-256 8c7857a3b26ac13312ed5901f1089f0351dfd958d19e96242d557e25c1498a95

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: bcl-2.3.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 96.4 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for bcl-2.3.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f65e9f347b76964d91294964559da05cdcefb1f0bdfe90b6173892de3598a810
MD5 1e36033911ee8ce1c2ba3baa63570785
BLAKE2b-256 302ea78ec72cfc2d6f438bd2978e81e05e708953434db8614a9f4f20bb7fa606

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp310-abi3-win32.whl.

File metadata

  • Download URL: bcl-2.3.1-cp310-abi3-win32.whl
  • Upload date:
  • Size: 88.7 kB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for bcl-2.3.1-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 28f55e08e929309eacf09118b29ffb4d110ce3702eef18e98b8b413d0dfb1bf9
MD5 1bde6e170e433b9c22abe7c954402896
BLAKE2b-256 36e3c860ae7aa62ddacf0ff4e1d2c9741f0d2ab65fec00e3890e8ac0f5463629

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bcl-2.3.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a7696201b8111e877d21c1afd5a376f27975688658fa9001278f15e9fa3da2e0
MD5 8930876d54e51a2499e9f84db303053e
BLAKE2b-256 1aa7984bdb769c5ad2549fafc9365b0f6156fbeeec7df524eb064e65b164f8d0

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp310-abi3-macosx_10_10_universal2.whl.

File metadata

File hashes

Hashes for bcl-2.3.1-cp310-abi3-macosx_10_10_universal2.whl
Algorithm Hash digest
SHA256 cf59d66d4dd653b43b197ad5fc140a131db7f842c192d9836f5a6fe2bee9019e
MD5 131ab99a7677425d15c3b631dc83ffba
BLAKE2b-256 8293f712cab57d0424ff65b380e22cb286b35b8bc0ba7997926dc18c8600f451

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: bcl-2.3.1-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 96.4 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for bcl-2.3.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 52cf26c4ecd76e806c6576c4848633ff44ebfff528fca63ad0e52085b6ba5aa9
MD5 347c71632c090f65b717336e43c70d39
BLAKE2b-256 9e45302d6712a8ff733a259446a7d24ff3c868715103032f50eef0d93ba70221

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp39-abi3-win32.whl.

File metadata

  • Download URL: bcl-2.3.1-cp39-abi3-win32.whl
  • Upload date:
  • Size: 88.7 kB
  • Tags: CPython 3.9+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for bcl-2.3.1-cp39-abi3-win32.whl
Algorithm Hash digest
SHA256 a5823f1b655a37259a06aa348bbc2e7a38d39d0e1683ea0596b888b7ef56d378
MD5 bb9822df7556aa6b72620d57e4896de0
BLAKE2b-256 7f94a3613caee8ca933902831343cc1040bcf3bb736cc9f38b2b4a7766292585

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bcl-2.3.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 97117d57cf90679dd1b28f1039fa2090f5561d3c1ee4fe4e78d1b0680cc39b8d
MD5 842ec6059c93740a9fe34fb2558f9485
BLAKE2b-256 b5f92be5d88275d3d7e79cdbc8d52659b02b752d44f2bf90addb987d1fb96752

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp39-abi3-macosx_10_10_universal2.whl.

File metadata

File hashes

Hashes for bcl-2.3.1-cp39-abi3-macosx_10_10_universal2.whl
Algorithm Hash digest
SHA256 bb695832cb555bb0e3dee985871e6cfc2d5314fb69bbf62297f81ba645e99257
MD5 f5849679d4aed6086bc588280f622ddb
BLAKE2b-256 08ada46220911bd7795f9aec10b195e1828b2e48c2015ef7e088447cba5e9089

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp39-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for bcl-2.3.1-cp39-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 0922349eb5ffd19418f46c40469d132c6e0aea0e47fec48a69bec5191ee56bec
MD5 f95dde4e40926de14765423881da3fed
BLAKE2b-256 d83ae8395071a89a7199363990968d438b77c55d55cce556327c98d5ce7975d1

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: bcl-2.3.1-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 96.4 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for bcl-2.3.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a7312d21f5e8960b121fadbd950659bc58745282c1c2415e13150590d2bb271e
MD5 aa18c5e9bb197f0fabfa0ddf7bbf14d9
BLAKE2b-256 85e3a0e02b0da403503015c2196e812c8d3781ffcd94426ce5baf7f4bbfa8533

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp38-abi3-win32.whl.

File metadata

  • Download URL: bcl-2.3.1-cp38-abi3-win32.whl
  • Upload date:
  • Size: 88.7 kB
  • Tags: CPython 3.8+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for bcl-2.3.1-cp38-abi3-win32.whl
Algorithm Hash digest
SHA256 1d8e0a25921ee705840219ed3c78e1d2e9d0d73cb2007c2708af57489bd6ce57
MD5 1a6b9d25c509a5761c8aa010cdf80943
BLAKE2b-256 6fff25eaaf928078fc266d5f4cd485206acaec43c6a9311cf809114833bc24c4

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bcl-2.3.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 447835deb112f75f89cca34e34957a36e355a102a37a7b41e83e5502b11fc10a
MD5 b5a72a7615a06dd035766ae185e43496
BLAKE2b-256 7b15c244b97a2ffb839fc763cbd2ce65b9290c166e279aa9fc05f046e8feb372

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp38-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for bcl-2.3.1-cp38-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f6d551e139fa1544f7c822be57b0a8da2dff791c7ffa152bf371e3a8712b8b62
MD5 45ad06a97361a0cf23df6f1ea2def31f
BLAKE2b-256 ab7a06d9297f9805da15775615bb9229b38eb28f1e113cdd05d0e7bbcc3429e4

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: bcl-2.3.1-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 96.4 kB
  • Tags: CPython 3.7+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for bcl-2.3.1-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fb778e77653735ac0bd2376636cba27ad972e0888227d4b40f49ea7ca5bceefa
MD5 7a8459c6fa85a448d712444a92bdcf25
BLAKE2b-256 26696fab32cd6888887ed9113b806854ac696a76cf77febdacc6c5d4271cba8e

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp37-abi3-win32.whl.

File metadata

  • Download URL: bcl-2.3.1-cp37-abi3-win32.whl
  • Upload date:
  • Size: 88.7 kB
  • Tags: CPython 3.7+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.2

File hashes

Hashes for bcl-2.3.1-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 17d2e7dbe852c4447a7a2ff179dc466a3b8809ad1f151c4625ef7feff167fcaf
MD5 14f5fb8266e8270c01dd6863e6d9adc7
BLAKE2b-256 5fa82714e3f7d5643f487b0ecd49b21fa8db2d9572901baa49a6e0457a3b0c19

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bcl-2.3.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 99aff16e0da7a3b678c6cba9be24760eda75c068cba2b85604cf41818e2ba732
MD5 743dfbcb3a7a9ca55c477b0f1e38034a
BLAKE2b-256 001a20ea61d352d5804df96baf8ca70401b17db8d748a81d4225f223f2580022

See more details on using hashes here.

File details

Details for the file bcl-2.3.1-cp37-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for bcl-2.3.1-cp37-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 edb8277faee90121a248d26b308f4f007da1faedfd98d246841fb0f108e47db2
MD5 d650f4b9e32c1e96d90215a8cbb33dd0
BLAKE2b-256 25f063337a824e34d0a3f48f2739d902c9c7d30524d4fc23ad73a3dcdad82e05

See more details on using hashes here.

Supported by

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