Use Python's Pickle Module Safely
Project description
SecPickle
We all know that the Python Pickle module is not secure because arbitrary code can be executed. The function of secpickle
is to guarantee that you will only unzip files that were generated by you, avoiding reading unknown files.
How to use
The functions available in secpickle
are:
- load()
- loads()
- dump()
- dumps()
Only one thing changes in using these functions: an argument called key
has been added to each of them. The key is requested so that a unique hash can be used to prove that file was created by you. The more complex your key, the greater the security.
The same key used for dump must be used to load the file. Otherwise, the IntegrityUnconfirmedError
exception will be thrown, indicating, as the name implies, that it is not possible to confirm whether that file was created by you.
from secpickle import secpickle
data = [{'name': 'SecPickle'}]
key = 'this-is-my-secret-key'
with open('data', 'wb') as file:
secpickle.dump(data, file, key)
with open('data', 'rb') as file:
result = secpickle.load(file, key)
print(result)
License
BSD 3-Clause License
Copyright (c) 2023, Firlast
This project uses the BSD 3-Clause License, please read the license for more informations.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file secpickle-0.1.0.tar.gz
.
File metadata
- Download URL: secpickle-0.1.0.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4cbff5d0409e9449e5e8198b912883516a9e41d3b2c0600744e3e603c820480 |
|
MD5 | 9d77991be072e28067564f10ce3fbda9 |
|
BLAKE2b-256 | b2d379c57e686050a71de7617bda65f20714ce9cbf8d450eaad8a76a0ecef8af |