crypto
- class python_plugins.crypto.simple_fernet.SimpleFernet(key: str | bytes | None = None)
A simple wrapper around cryptography.fernet.Fernet for encryption and decryption.
- Parameters:
key (str | bytes | None) – The key used for encryption and decryption. If None, a new key will be generated.
Examples
>>> fernet = SimpleFernet("my_secret_key") >>> encrypted = fernet.encrypt("Hello, World!") >>> decrypted = fernet.decrypt(encrypted) >>> assert decrypted == "Hello, World!"
- class python_plugins.crypto.aes_cipher.AesCipher(key=None, iv=None)
Cipher with aes. For example:
msg = b"a secret message" cipher = AesCipher() cipher.generate_key() print(cipher.key,cipher.iv) cipher.generate_cipher() encryptor = cipher.create_encryptor() ct = encryptor.update(cipher.pad(msg)) + encryptor.finalize() decryptor = cipher.create_decryptor() unct = decryptor.update(ct) + decryptor.finalize() unpad_data = cipher.unpad(unct)
- class python_plugins.crypto.txtfile_cipher.TxtFileCipher
Class to encrypt/decrypt text files with PBKDF2Fernet.
- decrypt_txtfile(fin, fout=None, password=None)
decrypt text file. examples:
decrypt_txtfile("test.txt") # output to print decrypt_txtfile("test.txt", password="mypassword") decrypt_txtfile("test.txt", fout=".") # output to test.txt_2 decrypt_txtfile("test.txt", "test.txt.dec") # output to test.txt.dec
- encrypt_txtfile(fin, fout=None, password=None, skip_password=False)
encrypt text file. example:
encrypt_txtfile("test.txt") # output to print, password input encrypt_txtfile("test.txt", "test.txt.enc") # output to test.txt.enc encrypt_txtfile("test.txt", password="mypassword") encrypt_txtfile("test.txt", skip_password=True) # skip password input, use random password encrypt_txtfile("test.txt", fout=".") # output to test.txt_1
output format:
<original file content> =SPLIT.HERE= prompt password=... salt=... iterations=... -<encrypted content>
- class python_plugins.crypto.tarmix.TarMix
- compress(file_or_dir, archive_path=None)
Compress file_or_dir into a tar.gz archive.
examples:
compress("myfile.txt") # output to myfile.txt.tar.gz compress("myfolder") # output to myfolder.tar.gz compress("myfile.txt", "archive.tar.gz")
- mix(file_or_dir, archive_path=None)
Mix file_or_dir into a custom encrypted tar.gz archive.
examples:
mix("myfile.txt") # output to myfile.txt.tar.gz with random password mix("myfolder", "archive.tar.gz") # output to archive.tar.gz with random password
- uncompress(archive_path, output_path=None)
Uncompress tar.gz archive into output_path.
examples:
uncompress("archive.tar.gz") # output to folder archive_extracted uncompress("archive.tar.gz", "output_folder") # output to output_folder
- unmix(archive_path, output_path=None)
Unmix custom encrypted tar.gz archive into output_path.
examples:
unmix("archive.tar.gz") # output to folder archive_extracted unmix("archive.tar.gz", "output_folder") # output to output_folder