module filehelper.encryption
¶
Short summary¶
module pyquickhelper.filehelper.encryption
Encryption functionalities.
Inspired from AES encryption of files in Python with PyCrypto
Classes¶
class |
truncated documentation |
---|---|
raised if an issue happen during encryption |
Functions¶
function |
truncated documentation |
---|---|
Takes the output of |
|
Decrypts a file using AES (CBC mode) with the given key. The function relies on module pycrypto, cryptography, … |
|
Encrypts a file using AES (CBC mode) with the given key. The function relies on module pycrypto, cryptography, … |
|
Returns an encryptor with method encrypt and decrypt. |
|
Converts filename and out_filename as streams. |
Documentation¶
Encryption functionalities.
Inspired from AES encryption of files in Python with PyCrypto
- exception pyquickhelper.filehelper.encryption.EncryptionError[source]¶
Bases:
Exception
raised if an issue happen during encryption
- pyquickhelper.filehelper.encryption.close_input_output(in_size, in_close, in_stream, out_close, out_return, out_stream)[source]¶
Takes the output of
open_input_output
and closes streams and return expected values.- Parameters:
in_size – size of input
in_close – should it close the input stream
in_stream – input stream
out_close – should it closes the output stream
out_return – should it returns something
out_stream – output stream
- Returns:
None or content of output stream
- pyquickhelper.filehelper.encryption.decrypt_stream(key, filename, out_filename=None, chunksize=24576, algo='AES')[source]¶
Decrypts a file using AES (CBC mode) with the given key. The function relies on module pycrypto, cryptography, algoritm AES, Fernet.
- Parameters:
key – The encryption key - a string that must be either 16, 24 or 32 bytes long. Longer keys are more secure. If the data to encrypt is in bytes, the key must be given in bytes too.
filename – bytes or Name of the input file
out_filename – if None, the returns bytes
chunksize – Sets the size of the chunk which the function uses to read and encrypt the file. Larger chunk sizes can be faster for some files and machines. chunksize must be divisible by 16.
algo – AES (pycryptodomex) of or fernet (cryptography)
- Returns:
filename or bytes
- pyquickhelper.filehelper.encryption.encrypt_stream(key, filename, out_filename=None, chunksize=262144, algo='AES')[source]¶
Encrypts a file using AES (CBC mode) with the given key. The function relies on module pycrypto, cryptography, algoritm AES, Fernet.
- Parameters:
key – The encryption key - a string that must be either 16, 24 or 32 bytes long. Longer keys are more secure. If the data to encrypt is in bytes, the key must be given in bytes too.
filename – bytes or Name of the input file
out_filename – if None, the returns bytes
chunksize – Sets the size of the chunk which the function uses to read and encrypt the file. Larger chunk sizes can be faster for some files and machines. chunksize must be divisible by 16.
algo – AES (PyCryptodomex) of or fernet (cryptography)
- Returns:
filename or bytes
- pyquickhelper.filehelper.encryption.get_encryptor(key, algo='AES', chunksize=16777216, **params)[source]¶
Returns an encryptor with method encrypt and decrypt.
- Parameters:
key – key
algo – AES or fernet
chunksize – Fernet does not allow streaming
params – additional parameters
- Returns:
encryptor, origsize
- pyquickhelper.filehelper.encryption.open_input_output(filename, out_filename=None)[source]¶
Converts filename and out_filename as streams.
- Parameters:
filename – bytes or filename or BytesIO
out_filename – BytesIO or filename or None
- Returns:
in_size, in_close, in_stream, out_close, out_return, out_stream