xq package

Subpackages

Submodules

xq.config module

Module contents

class xq.XQ(api_key=None, dashboard_api_key=None)

Bases: object

decrypt_file(encryptedText: bytes, key: bytes, algorithm: {'OTP': <class 'xq.algorithms.otp_encryption.OTPEncryption'>, 'AES': <class 'xq.algorithms.aes_encryption.AESEncryption'>} = 'OTP', nonce: bytearray | None = None) StringIO

decrypt a given bytes string back into a FileLike object

Parameters:
  • encryptedText (bytes) – encrypted file contents

  • key (bytes) – encryption key

Returns:

FileLike StringIO handle

Return type:

StringIO

decrypt_message(encryptedText: bytes, key: bytes, algorithm: {'OTP': <class 'xq.algorithms.otp_encryption.OTPEncryption'>, 'AES': <class 'xq.algorithms.aes_encryption.AESEncryption'>} = 'OTP', nonce: bytearray | None = None)

decrypt a previoulsy encrypted string

Parameters:
  • encryptedText (bytes) – encrypted text to decrypt

  • key (bytes) – encryption key used to encrypt/decrypt

  • algorithm (Algorithms) – algorithm used to encrypt/decrypt

  • nonce (bytearray) – nonce provided from original encryption

Returns:

decrypted text

Return type:

str

encrypt_file(fileObj: ~typing.TextIO, key: bytes, algorithm: {'OTP': <class 'xq.algorithms.otp_encryption.OTPEncryption'>, 'AES': <class 'xq.algorithms.aes_encryption.AESEncryption'>} = 'OTP') bytearray

encrypt the contents of a given file object

Parameters:
  • fileObj (TextIO) – FileLike object to encrypt

  • key (bytes) – encryption key to use, NOTE: may be expanded

Returns:

encrypted text, encryption key

Return type:

tuple

encrypt_message(text: str, key: bytes, algorithm: {'OTP': <class 'xq.algorithms.otp_encryption.OTPEncryption'>, 'AES': <class 'xq.algorithms.aes_encryption.AESEncryption'>} = 'OTP')

encrypt a string

Parameters:
  • text (str) – string to encrypt

  • key (bytes, defaults to None) – encryption key to use to encrypted text

  • algorithm (Algorithms, defaults to AES) – the encryption algorithm to use

Returns:

ciphertext, nonce, tag from encryption

Return type:

tuple(bytes)

expand_key(data: bytes, key: bytes) bytes

expand a key to the size of the text to be encrypted

Parameters:
  • data (bytes) – data you are going to encrypt

  • key (bytes, defaults to None) – encryption key you were going to utilize to encrypt the data

Returns:

expanded key to utilize for encryption

Return type:

bytes

generate_key_from_entropy()

helper method for automatically requesting entropy and shuffling key

Returns:

generated encryption key from entropy

Return type:

bytes

magic_decrypt(magic_bundle)

easy button decryption: decrypt a magic encrypted with it’s magic bundle

Parameters:

magic_bundle (tuple) – magic bundle created by magic_encryption

Returns:

decrypted item

Return type:

any

magic_encrypt(thing_to_encrypt: any, recipients: List[str])

easy button encryption: encrypt something with an entropy generated encryption key, and store the key in XQ

Parameters:
  • thing_to_encrypt (any) – something to encrypt (i.e. text, file path string, etc)

  • recipients (List[str]) – list of recipient emails

Raises:

XQException – _description_

Returns:

magic bundle, used for decryption

Return type:

tuple