decrypt_str¶
-
EncryptHelper.decrypt_str(data: Union[str, bytes], key: Union[str, bytes] = None) → str[source]¶ Decrypts
datapreviously encrypted usingencrypt_str()with the same Fernet compatiblekey, and returns the decrypted version as a string.The
keycannot just be a random “password”, it must be a 32-byte key encoded with URL Safe base64. Use the methodgenerate_key()to create a Fernet compatible encryption key.Under the hood, Fernet uses AES-128 CBC to encrypt the data, with PKCS7 padding and HMAC_SHA256 authentication.
If the
keyparameter isn’t passed, or is empty (None / “”), then it will attempt to fall back toencrypt_key- if that’s also empty, EncryptKeyMissing will be raised.- Parameters
- Raises
EncryptKeyMissing – Either no key was passed, or something is wrong with the key.
EncryptionError – Something went wrong while attempting to decrypt the data
- Return str decrypted_data
The decrypted data as a string