PyFLocker
Python Cryptographic (File Locking) Library
Lock as in Lock and Key.
Installation
Use pip or pip3 to install PyFLocker
pip install pyflocker
or
pip3 install pyflocker
Introduction
PyFLocker aims to be a highly stable and easy to use cryptographic library. Before you read on, check if you agree to at least one of these points:
-
PyCryptodome(x)andpyca/cryptographyhave very different public interfaces, which makes remembering all the imports very difficult, and leaves you reading docs under deadline. -
The interface of
pyca/cryptographyis very difficult to use, let alone remember the import:from cryptography.hazmat.primitives.ciphers.algorithms import AES from cryptography.hazmat.primitives.ciphers import Modes ... from cryptography.hazmat.backends import default_backend # and so on...
-
You wish that only if
pyca/cryptographyhad been as easy to use asPycryptodome(x), it would have made life more easy. -
You sometimes think that the file encryption script you wrote were somehow faster and played with both backends very well, but you weren't sure what to do.
- And all the other solutions (and nonsolutions!) on the internet just confuses you more!
PyFLocker uses well established libraries as its backends and expands upon them. This gives you the ultimate ability to cherry-pick the primitives from a specific backend without having to worry about backend itself, as PyFLocker handles it for you.
You can find more information in the documentation.
Features
Not a "Yet Another Cryptographic Library"
PyFLocker provides you a seamless interface to both the backends, and switching is very easy:
import os
from pyflocker.ciphers import AES, RSA, ECC
from pyflocker.ciphers.backends import Backends
key, nonce = os.urandom(32), os.urandom(16)
# Multiple backends - same API
enc = AES.new(True, key, AES.MODE_EAX, nonce, backend=Backends.CRYPTOGRAPHY)
rpriv = RSA.generate(2048, backend=Backends.CRYPTODOME)
epriv = ECC.generate("x25519", backend=Backends.CRYPTOGRAPHY)
Backend loading is done internally, and if a backend is explicitly specified, that is used as the default.
Ease of Use
PyFLocker provides reasonable defaults wherever possible:
from pyflocker.ciphers import RSA
priv = RSA.generate(2048)
with open("private_key.pem", "xb") as f:
key = priv.serialize(passphrase=b"random-chimp-event")
f.write(key)
Don't believe me, try to do the same operation with pyca/cryptography,
or just any other initialization.
In short, the API is very stable, clear and easy on developer's mind.
Writing into file or file-like objects
This is often a related problem when it comes to encryption, but think no more!
import os
from pyflocker.ciphers import AES
from pyflocker.ciphers.backends import Backends
key, nonce = os.urandom(32), os.urandom(16)
f1 = open("MySecretData.txt", "rb")
f2 = open("MySecretData.txt.enc", "xb")
enc = AES.new(
True,
key,
AES.MODE_EAX,
nonce,
backend=Backends.CRYPTOGRAPHY,
file=f1,
)
enc.update_into(f2)
tag = enc.calculate_tag()
You can also use BytesIO in place of file objects.
Directly encrypting files
Just want to encrypt your file with AES, and even with various available modes?
from pyflocker.locker import locker
from pyflocker.ciphers import AES
password = b"no not this"
locker(
"./MySuperSecretFile.txt",
password,
aes_mode=AES.MODE_CTR, # default is AES-GCM-256
)
# file stored as MySuperSecretFile.txt.pyflk
Find more examples here.
License
Metadata
Release files for PyFLocker 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyflocker-0.4.2.tar.gz | 67.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyflocker-0.4.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 136.7 kB
Release files / pyflocker-0.4.2.tar.gz
| Download URL | pyflocker-0.4.2.tar.gz |
|---|---|
| Size | 67.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9d7cd849c852f4ce803548478bd3d6e4510541dec76702ca6f9599407ab4cea1
|
|
BLAKE2b-256 checksum How to use checksums |
4ad530f119f265099073f881cc5e629e34e2c95e37770e9b769789dacc2c2a32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.15.0 CPython/3.12.3 Linux/6.5.0-1018-azure
|
Release files / pyflocker-0.4.2-py3-none-any.whl
| Download URL | pyflocker-0.4.2-py3-none-any.whl |
|---|---|
| Size | 68.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
39aeb7853acbfe991e29c4bf95c481fb324d6dff2f050ee1e2767aedfbd95ad7
|
|
BLAKE2b-256 checksum How to use checksums |
3bc14da9de475d391a2b9821efbaa621965992e40bcfe8f7bf55f925f7e5e954
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.15.0 CPython/3.12.3 Linux/6.5.0-1018-azure
|