Skip to main content

Databridges Python NaCl Wrapper Library

Databridges NACL wrapper gives you a simple write and read function using implementation of the secretbox encryption standard defined in NaCl.

Databridges NACL wrapper is available for

The above wrappers can be used to send encrypted messages between them.

The Databridges NACL wrapper for Python Language binding uses PyNaCl to deliver implementation of the secretbox encryption standard defined in NaCl.

Usage Overview

The following topics are covered:

Supported platforms

Supports Python versions +3.6

Installation.

You can use pip package manager to install the package.

pip3 install databridges_nacl_wrapper

Initialization

from databridges_nacl_wrapper import databridges_nacl_wrapper
secretData = databridges_nacl_wrapper()

Global Configuration

Required

The following is the required properties before using to dataBridges NaCl wrapper.

secretData.secret = '32 char alphanumeric string';
Properties Description
secret (string) 32 char alpha numeric string. NaCl encryption secret.

Encrypt data

To encrypt data using NaCl, databridges wrapper exposes a method named write, This will return encrypted data if successful else it will throw error.

write()

try:
    encData = secretData.write("Your Data.."); 
    print('Encrypted:', encData);
except Exception as err:
    print('Errors:', err.source , err.code , err.message);
Parameter Description
data (string) data to be encrypted.
Return Values Description
string Encrypted string.
Exceptions:
Source Code Description
DBLIB_NACL_WRAPPER INVALID_SECRET secret is not set with the wrapper instance.
DBLIB_NACL_WRAPPER INVALID_DATA If data is not passed to the function.
DBLIB_NACL_WRAPPER NACL_EXCEPTION Exceptions generated by NaCl library.

Decrypt data

To decrypt data using NaCl, databridges wrapper exposes a method named read, This will return decrypted data if successful else it will throw error.

read()

try:
    decData = secretData.read("<Encrypted data.>")
    print('Decrypted:', decData);
except Exception as err:
    print("Errors:", err.source, err.code, err.message)
Parameter Description
data (string) data to be encrypted.
Return Values Description
string Encrypted string.
Exceptions:
Source Code Description
DBLIB_NACL_WRAPPER INVALID_SECRET secret is not set with the wrapper instance.
DBLIB_NACL_WRAPPER INVALID_DATA If data is not passed to the function OR data is not a valid encrypted string.
DBLIB_NACL_WRAPPER NACL_EXCEPTION Exceptions generated by NaCl library.
DBLIB_NACL_WRAPPER NACL_DECRYPT_FAILED If decryption fails due to invalid secret or manipulated data.

How to use with Databridges Python Library

Below code shows how to integrate the NaCl wrapper with the Databridges library. After initialize you can use the wrapper library to encrypt and decrypt the data when publishing and receiving events.

# Initialize both databridges-sio-client-lib and databridges-nacl-wrapper
from  databridges_sio_client_lib import dBridges
from databridges_sio_client_lib.exceptions import dBError
from databridges_nacl_wrapper import databridges_nacl_wrapper

dbridge = dBridges()
secretData = databridges_nacl_wrapper()
secretData.secret = "Your32 char secret.";

# .... Your databridges code comes here.

# On Subscription success event.
async def on_SubscribeChannel(payload, metadata):
    try:
        # Encrypt data to publish
        encData = secretData.write('Your Data..')
        await self.subscribeChannel.publish('eventName', encData, 1)
    except Exception as err:
        print("Error: ", err.source, err.code, err.message)

self.subscribeChannel.bind("dbridges:subscribe.success", on_SubscribeChannel)

# On payload Received event.
async def on_EventReceived(payload, metadata):
    try:
        decData = secretData.read(payload)
        print('Decrypted:', decData);
    except Exception as err:
        print("Error: ", err.source, err.code, err.message) 

self.subscribeChannel.bind("eventName", on_EventReceived)

Change Log

License

DataBridges NaCl Wrapper is released under the MIT license.

    Copyright 2022 Optomate Technologies Private Limited.

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for databridges_nacl_wrapper 1.0.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 databridges_nacl_wrapper 1.0.1
File Size Uploaded
databridges_nacl_wrapper-1.0.1.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for databridges_nacl_wrapper 1.0.1
File Interpreter ABI Platform
databridges_nacl_wrapper-1.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 12.7 kB

Release files / databridges_nacl_wrapper-1.0.1.tar.gz

Download URL databridges_nacl_wrapper-1.0.1.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4d61798d554ca9639539302ada43fbc6222e220e6374336e3fcc9989fcb833e6
BLAKE2b-256 checksum
How to use checksums
1ad2a92d5e6156438986675049168981df608f6c5bf60e80ea53b04d676c50c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.18.4

Release files / databridges_nacl_wrapper-1.0.1-py2.py3-none-any.whl

Download URL databridges_nacl_wrapper-1.0.1-py2.py3-none-any.whl
Size 6.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
731f0d4414f60292deede5c1d0d6af5dcb85b1707697dd9ec6352363ebf7047c
BLAKE2b-256 checksum
How to use checksums
667cb61b7bc0c219014ff94210bd0059a595445f8124fc315149e69d48e0ba7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.18.4

Release history Release notifications | RSS feed

This release

1.0.1 This release

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