Client SDK Version 1.8.0
Ionic Security client SDK for Python users
ChunkCrypto Overview

Introduction to ChunkCrypto

The ChunkCrypto module supports encryption and decryption of all small to medium length text and binary data. It is designed specifically for producing ciphertext that is encoded within the ASCII (base64) character set and is as small as possible (typically a small percentage larger than the plaintext) for ease of use, storage, transfer, etc. This differs from the FileCrypto module (FileCipher Overview), which for the most part emits binary ciphertext and is not particularly concerned about any overhead introduced.


ChunkCryptoLib Thread Safety

ChunkCrypto is not thread-safe. All classes in the ChunkCrypto module are not thread-safe and should not be used as a shared resource between concurrent threads. In order to use objects in a multi-threaded environment, it is recommended to create one object per thread.


Chunk Cipher Classes


The Automatic Chunk Cipher

ionicsdk.chunkcipher.ChunkCipherAuto is a special cipher in the sense that it does not represent a format of its own, but instead it automatically chooses the correct chunk cipher to use (e.g. ionicsdk.chunkcipher.ChunkCipherV2) based on the contents of the chunk being encrypted / decrypted. Using this cipher is recommended in most cases since it simplifies the code of the consuming application. An example can be seen here: Example Usage - Simple.

By default, when encrypting using ionicsdk.chunkcipher.ChunkCipherAuto, the result is encoded using the ionicsdk.chunkcipher.ChunkCipherV2 format. When decrypting using ionicsdk.chunkcipher.ChunkCipherAuto, the appropriate ChunkCipher is used.


Example Usage - Simple

import ionicsdk
# Create an agent and initialize it using all defaults.
myAgent = ionicsdk.Agent()
# Create an automatic chunk cipher using the initialized agent.
cipher = ionicsdk.ChunkCipherAuto(myAgent)
# Encrypt a small chunk of text and then decrypt it.
encryptedString = cipher.encryptstr("This is a text message that I want to be protected")
# Decrypt the text that we just encrypted.
recoveredString = cipher.decryptstr(encryptedString)


Example Usage - Advanced

import ionicsdk
# Create an agent and initialize it using all defaults.
myAgent = ionicsdk.Agent()
# Create an automatic chunk cipher using the initialized agent.
cipher = ionicsdk.ChunkCipherAuto(myAgent)
# Use a ChunkCipherEncryptAttributes object to provide key attributes that
# describe some aspects of the text being encrypted.
attrDict = {'clearance':['secret'],'test1':['testA','testB']}
mutableAttrDict = {'Date':['Jan 1', '1970'], 'Salary':['Hamburgers',]}
metaDict = {'meta':'data'}
encryptAttributes = ionicsdk.ChunkCipherEncryptAttributes(attrDict, metaDict, mutableAttrDict)
# Encrypt a test file.
encryptedString = cipher.encryptstr2("Hi David! Please contact me at johndoe@example.com", encryptAttributes)
# Decrypt the file that we just encrypted.
decryptAttributes = ionicsdk.ChunkCipherDecryptAttributes(metaDict)
recoveredString = cipher.decryptstr2(encryptedString,decryptAttributes)