Security

A simple helper for “I want to encrypt this chunk of text with a password” Requires installation of the cryptography library (q2 add_dependency cryptography)

Uses Cryptography’s fernet symmetrical encryption algorithm: https://cryptography.io/en/latest/fernet/

Usage:

from q2_sdk.core import security

unencrypted_string = "I am in need to encrypting"
secret_key = "supersecret"
encrypted_string = security.encrypt(unencrypted_string, secret_key)
new_unencrypted_string = security.decrypt(encrypted_string, secret_key)
assert unencrypted_string == new_unencrypted_string
q2_sdk.core.security.decrypt(encrypted_data, password)[source]

Takes in encrypted bytes and a password and returns unencrypted bytes

Parameters:
  • encrypted_data (bytes) – Encrypted Bytes

  • password (bytes) – Passphrase to decrypt with

Return type:

bytes

q2_sdk.core.security.encrypt(data, password)[source]

Takes in raw text and a password and returns encrypted bytes

Parameters:
  • data (bytes | str) – Raw text

  • password (bytes) – Passphrase to encrypt with

Return type:

bytes