cipher#
- class windtalker.cipher.BaseCipher[source]#
Base cipher class.
Any cipher utility class that using any encryption algorithm can be inherited from this base class. The only method you need to implement is
BaseCipher.encrypt()
andBaseCipher.decrypt()
. Because once you can encrypt binary data, then you can encrypt text, file, and directory.- encrypt(binary: bytes, *args, **kwargs) bytes [source]#
Overwrite this method using your encrypt algorithm.
- Parameters:
binary – binary data you need to encrypt
- Returns:
encrypted_binary, encrypted binary data
- decrypt(binary: bytes, *args, **kwargs) bytes [source]#
Overwrite this method using your decrypt algorithm.
- Parameters:
binary – binary data you need to decrypt
- Returns:
decrypted_binary, decrypted binary data
- encrypt_file(path: Union[str, Path, Path], output_path: Optional[Union[str, Path, Path]] = None, overwrite: bool = False, stream: bool = True, enable_verbose: bool = True, **kwargs)[source]#
Encrypt a file. If output_path are not given, then try to use the path with a surfix appended. The default automatical file path handling is defined here
windtalker.files.get_encrypted_file_path()
- Parameters:
path – path of the file you need to encrypt
output_path – encrypted file output path
overwrite – if True, then silently overwrite output file if exists
stream – if it is a very big file, stream mode can avoid using too much memory
enable_verbose – trigger on/off the help information
- decrypt_file(path: Union[str, Path, Path], output_path: Optional[Union[str, Path, Path]] = None, overwrite: bool = False, stream: bool = True, enable_verbose: bool = True, **kwargs)[source]#
Decrypt a file. If output_path are not given, then try to use the path with a surfix appended. The default automatical file path handling is defined here
windtalker.files.recover_path()
- Parameters:
path – path of the file you need to decrypt
output_path – decrypted file output path
overwrite – if True, then silently overwrite output file if exists
stream – if it is a very big file, stream mode can avoid using too much memory
enable_verbose – boolean, trigger on/off the help information
- encrypt_dir(path: Union[str, Path, Path], output_path: Optional[Union[str, Path, Path]] = None, overwrite: bool = False, stream: bool = True, enable_verbose: bool = True)[source]#
Encrypt everything in a directory.
- Parameters:
path – path of the dir you need to encrypt
output_path – encrypted dir output path
overwrite – if True, then silently overwrite output file if exists
stream – if it is a very big file, stream mode can avoid using too much memory
enable_verbose – boolean, trigger on/off the help information
- decrypt_dir(path: Union[str, Path, Path], output_path: Optional[Union[str, Path, Path]] = None, overwrite: bool = False, stream: bool = True, enable_verbose: bool = True)[source]#
Decrypt everything in a directory.
- Parameters:
path – path of the dir you need to decrypt
output_path – decrypted dir output path
overwrite – if True, then silently overwrite output file if exists
stream – if it is a very big file, stream mode can avoid using too much memory
enable_verbose – boolean, trigger on/off the help information