ExperimentSession.encrypt()#

ExperimentSession.encrypt(data: Union[str, int, float]) str[source]#

Encrypts the input and returns the encrypted string.

Parameters

data – Input object that you want to encrypt. If the input is None, the function will return None.

Returns

Encrypted data

Return type

str

Raises
  • AlfredError – If no encryptor is available, which usually

  • means that no encryption key was provided.

Notes

In web experiments deployed via mortimer, a safe, user-specific secret key will be used for encryption.

For encryption in local experiments, you must provide an encryption key yourself. You have two options:

  1. Save the key to the environment variable “ALFRED_ENCRYPTION_KEY”. Alfred will look for this variable and use the key provided here.

  2. Create a secrets.conf file in your experiment directory and define the option “key” in section “encryption”. If you define this option, this key will be preferred over the key from the environment variable.

The key must be a string containing a valid fernet key, generated by cryptography.fernert.Fernet.generate_key().

A string key can be generated with a few lines of python code:

>>> from cryptography.fernert import Fernet
>>> key = Fernet.generate_key()
>>> print(key.decode())
biNJTMLgFYc5fKAd-DNi1ioh44BTnfAQGbozpDcXZ-M=

You can copy-paste a key that you generated this way into your environment variable or secrets.conf (but obviously DON’T copy the key from this public example!).