Package: onqlave-python-dev
This Python SDK is designed to help developers easily integrate OnqlaveEncryption As A Serviceinto their python backend.Table of ContentsDescriptionTable of ContentsFeaturesInstallationRequirementsConfigurationUsageEncryptDecryptEncrypt StreamDecrypt StreamReporting a VulnerabilityFeaturesEncrypt/decrypt pieces of informationEncrypt/decrypt stream of dataInstallationRequirementsPython 3.8 and aboveConfigurationTo install, simply using this command:pipinstallonqlave-python-sdk-pilotYou can also check thepackage detail on PyPIUsageTo use this SDK, you firstly need to obtain credentials to access an Onqlave Arx by signing up toOnqlaveand following instruction to create your first Onqlave Arx. Documentation can be found atOnqlave Technical Documentation.TheOnqlave Pythonmodule 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 theexamples/directory.)fromonqlave.encryptionimportoptionsfromonqlave.encryption.encryptionimportEncryptionfromonqlave.credentials.credentialsimportCredentialfromonqlave.connection.clientimportRetrySettingscred_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)EncryptTo encrypt data, use theencrypt(plaintext: bytearray, associated_data: bytearray)method of theEncryptionservice. Theplaintextparameter is thebytearrayrepresentation of data you are wishing to encrypt. Theassociated_dataparameter thebytearrayrepresentation 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 hereassociated_data="auth"# your authentication data goes herecipher_text=encryption_engine.encrypt(plaintext.encode(),associated_data.encode())DecryptTo decrypt data, use thedecrypt(cipher_data: bytearray, associated_data: bytearray)method of theEncryptionservice. Thecipher_dataparameter is thebytearrayrepresentation of data you are wishing to decrypt (previousely encrypted). Theassociated_dataparameter thebytearrayrepresentation 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 StreamTo encrypt stream of data, use theencrypt_stream(plain_stream io.Reader, cipher_stream io.Writer, associated_data bytearray)method of theEncryptionservice. Theplain_streamparameter is theio.Readerstream of data you are wishing to encrypt. Thecipher_streamparameter is theio.Writestream you are wishing to write the cipher data to. Theassociated_dataparameter thebytearrayrepresentation 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 StreamTo decrypt data, use thedecrypt_stream(cipher_stream io.io.BytesIO, plain_stream io.BytesIO, associated_data []byte)method of theEncryptionservice. Thecipher_streamparameter is theio.BytesIO()stream of data you are wishing to decrypt and it was originally encrypted usingencrypt_stream. Theplain_streamparameter is theio.BytesIO()stream you are wishing to write the plain data back to. Theassociated_dataparameter thebytearrayrepresentation 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)withopen("path to your decrypted file","wb")asresult:result.write(decrypted_stream.read())Reporting a VulnerabilityIf you discover a potential security issue in this project, please reach out to us atsecurity@onqlave.com. Please do not create public GitHub issues or Pull Requests, as malicious actors could potentially view them.