Skip to main content

This Python SDK is designed to help developers easily integrate Onqlave Encryption As A Service into their python backend.

Project description

This Python SDK is designed to help developers easily integrate Onqlave Encryption As A Service into their python backend.

CI GitHub release License

Table of Contents

Features

  • Encrypt/decrypt pieces of information
  • Encrypt/decrypt stream of data

Installation

Requirements

  • Python 3.8 and above

Configuration

To install, simply using this command:

pip install onqlave-python-sdk-pilot

You can also check the package detail on PyPI

Usage

To use this SDK, you firstly need to obtain credentials to access an Onqlave Arx by signing up to Onqlave and following instruction to create your first Onqlave Arx. Documentation can be found at Onqlave Technical Documentation.

The Onqlave Python module is used to perform operations on the configured Arx such as encrypting and decryptin for an Onqlave Arx.

To use this module, an Onqlave client should be initialized as follows. (Please note that there are 3 ways of loading configurations specified in the examples/ directory.)

from onqlave.encryption import options
from onqlave.encryption.encryption import Encryption
from onqlave.credentials.credentials import Credential
from onqlave.connection.client import RetrySettings

cred_file_path = "credentials.json"

arx_option = options.ArxOption()
credential_option = Credential()

arx_option.load_arx_url_from_json(cred_file_path)
credential_option.load_config_from_json(cred_file_path)

retry_option = RetrySettings(count=1,wait_time=1,max_wait_time=2) 

encryption_engine = Encryption(
    debug_option=debug_option,
    arx_option=arx_option,
    credential_option=credential_option,
    retry_setting=retry_option
)

Encrypt

To encrypt data, use the encrypt(plaintext: bytearray, associated_data: bytearray) method of the Encryption service. The plaintext parameter is the bytearray representation of data you are wishing to encrypt. The associated_data parameter the bytearray representation of associated data which can be used to improve the authenticity of the data (it is not mandatory), as shown below.

plaintext = "hello world" # your data goes here
associated_data = "auth" # your authentication data goes here
cipher_text = encryption_engine.encrypt(plaintext.encode(), associated_data.encode())

Decrypt

To decrypt data, use the decrypt(cipher_data: bytearray, associated_data: bytearray) method of the Encryption service. The cipher_data parameter is the bytearray representation of data you are wishing to decrypt (previousely encrypted). The associated_data parameter the bytearray representation of associated data which can be used to improve the authenticity of the data (it is not mandatory), as shown below.

decrypted_ciphertext = encryption_engine.decrypt(cipher_text,associated_data.encode())

Encrypt Stream

To encrypt stream of data, use the encrypt_stream(plain_stream io.Reader, cipher_stream io.Writer, associated_data bytearray) method of the Encryption service. The plain_stream parameter is the io.Reader stream of data you are wishing to encrypt. The cipher_stream parameter is the io.Write stream you are wishing to write the cipher data to. The associated_data parameter the bytearray representation of associated data which can be used to improve the authenticity of the data (it is not mandatory), as shown below.

plain_file_stream = open("path to your plaintext file","rb")
plain_stream = io.BytesIO(plain_file_stream.read())
cipher_stream = io.BytesIO()
    
encryption_engine.encrypt_stream(plain_stream,cipher_stream,associated_data.encode())
cipher_stream.seek(0)

Decrypt Stream

To decrypt data, use the decrypt_stream(cipher_stream io.io.BytesIO, plain_stream io.BytesIO, associated_data []byte) method of the Encryption service. The cipher_stream parameter is the io.BytesIO() stream of data you are wishing to decrypt and it was originally encrypted using encrypt_stream. The plain_stream parameter is the io.BytesIO() stream you are wishing to write the plain data back to. The associated_data parameter the bytearray representation of associated data which can be used to improve the authenticity of the data (it is not mandatory), as shown below.

decrypted_stream = io.BytesIO()
encryption_engine.decrypt_stream(
    cipher_stream=cipher_stream,
    plain_stream=decrypted_stream,
    associated_data=associated_data.encode()
)
decrypted_stream.seek(0)

with open(
    "path to your decrypted file",
    "wb"
) as result:
    result.write(decrypted_stream.read())

Reporting a Vulnerability

If you discover a potential security issue in this project, please reach out to us at security@onqlave.com. Please do not create public GitHub issues or Pull Requests, as malicious actors could potentially view them.

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

onqlave-python-dev-0.1.0.tar.gz (24.7 kB view details)

Uploaded Source

Built Distribution

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

onqlave_python_dev-0.1.0-py3-none-any.whl (35.2 kB view details)

Uploaded Python 3

File details

Details for the file onqlave-python-dev-0.1.0.tar.gz.

File metadata

  • Download URL: onqlave-python-dev-0.1.0.tar.gz
  • Upload date:
  • Size: 24.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for onqlave-python-dev-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e970d94915f5605fc86b533e193c4b5f097332e6e3442bc7f1cb40bbb946c4dc
MD5 544e8240f7dcc54d5d833207d888c0f1
BLAKE2b-256 babb95925858bf75a802c99dc0eae8775d31bde1d2aa8c5086f51701039ab189

See more details on using hashes here.

File details

Details for the file onqlave_python_dev-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for onqlave_python_dev-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60af7a01a52ed9aa79bc207af69a3d778dc278bb19a82664824865aefaa12f46
MD5 5c667e5289d4812c03e88d55d0ad788f
BLAKE2b-256 6569617ccf9f3ca7e3e3831181e1f016eb73a99563202af6cd30ef830880fa74

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