A small package for safe data serialization and encryption
Project description
encr
Makes serializing safer and easier by encrypting your data with a custom password. You can get a history of all added functionalities between updates in the CHANGELOG.md file. You can get a list of features that should come in the future in the COMING_SOON.MD file.
Dependencies
This package currently depends on cryptography, which at the time of writing depends on cffi, which again depends on pycparser.
Summing up, along with this package other 3 will be installed:
- cryptography
- cffi
- pycparser
Usage
The encr class: safe data encryption and serialization with custom password
Creating an encr instance
from encr import encr
e = encr("Password")
encr takes two arguments:
- password, the string that will be hashed and converted into a key for encryption
- clvl (optional), the compression level. Read zlib's documentation for information about that.
Changing the password mid-script: setkey
e.setkey("New password")
setkey changes the key used for serialization. It takes one argument:
- password, the string that will be hashed and converted into a key for encryption
Warning
Remember: changing the password of an encr instance will make all previously encrypted data unusable, until you create another instance with the original password or reset the existing one with setkey.
Changing the compression level mid-script
e.clvl = 5
clvl is an attribute, which means it is a variable and it can't be called as a function. Just set e.clvl like a normal variable.
Encrypting and decrypting: dumps and loads
serialized_object = e.dumps("foobar")
print(serialized_object)
b'gAAAAABj85Nfc5tnmOSwj_wlSvFUop-E5ifYmEQUa8n2Ld5cNw5mahzkA-OpBDA9ky21OJa7vcLfheRMKA4yJppp7_ot_bWyTJ9lU5-TXCaeSJO8hzy3T7Y=' deserialized_object = e.loads(serialized_object) print(deserialized_object) foobar
dumps serializes the object. It takes one argument:
- obj, the object to be encrypted
loads deserializes the object. It takes one argument:
- obj, the encrypted object to be deserialized
Saving a variable to a file: dump and load
e.dump("foobar", "file.encr")
print(e.load("file.encr"))
"foobar"
dump serializes the object and saves it in a file. It takes two arguments:
- obj, the object to be encrypted
- file, the file where your object will be saved
load takes a serialized object from a file and deserializes it. It takes one argument:
- file, the file where the object is stored
Encrypting a file: dumpfile and loadfile
e.dumpfile("MyFile.txt", "MyFile.encr")
e.loadfile("MyFile.encr", "MyFile.txt")
dumpfile reads a file and serializes it's content. It takes two arguments:
- file, the file to be encrypted
- dest, where your serialized file is saved
loadfile reads a file and deserializes it's content. It takes two arguments:
- file, the file to be decrypted
- dest, where your deserialized file is stored
Encrypting a folder: dumptree and loadtree
e.dumptree("MyFolder", "MyFile.encr")
e.loadtree("MyFile.encr")
dumptree reads all the files contained in a folder and in all it's subfolders and serializes both their content, name and position. It takes two arguments:
- file, the folder to be encrypted
- dest, the file where your serialized folder is saved
loadtree reads a file and restores the serialized tree. It takes one argument:
- file, the file containing the tree
Changing the password: setkey
e = encr("Password")
e.setkey("Password2")
You can change the key used for encryption anytime with the setkey method.
Miscellaneous: dumpfile, dumptree and load
e.dumptree("MyFolder", "MyData.encr")
print(e.load("MyData.encr")["MyFolder\\MyFile"].decode())
You can encrypt a file with dumpfile or a tree with dumptree and access it's content with load without having to decrypt it. dumpfile saves directly the file's contents in binary mode, dumptree saves all the filepaths and the file's contents in a dictionary.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file encr-0.1.0.1.tar.gz
.
File metadata
- Download URL: encr-0.1.0.1.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c5510f060c6b948c698fecbc6e28c783e016ed301d3beb99f4a1e1520e682e9 |
|
MD5 | 2c85c434bf148258d151f5ede2f85b9d |
|
BLAKE2b-256 | 23aca22ed055123bab9b524f75c872cde676e66ecee65339cae658da6922ce14 |
File details
Details for the file encr-0.1.0.1-py3-none-any.whl
.
File metadata
- Download URL: encr-0.1.0.1-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6eda26005b6cb3f922f311d3894aafadaa3ee1501623aa76fa13d0195bf23fe6 |
|
MD5 | 63ce3dfd2c76182db0e1f901955d6bf5 |
|
BLAKE2b-256 | dfcbcb497160036e6d16acbbf48b5a625dc145e581cd1d68dc7e577fe2e489ce |