Kinetic Encryption Key
Project description
KEK
Kinetic Encryption Key
This library provides symmetric, asymmetric (public key), hybrid (symmetric + asymmetric) encryption.
It was build using cryptography library and has uncomplicated interface.
Algorithms:
-
AES in CBC mode (128-256 bit)
-
RSA (2048-4096 bit)
Read the documentation on ReadTheDocs!
Installation
Use the package manager pip to install KEK.
pip install gnukek
Usage
Import key classes:
from KEK.hybrid import PrivateKEK, PublicKEK
To generate key:
private_key = PrivateKEK.generate()
To generate public key object:
public_key = private_key.public_key
To encrypt data:
encrypted = public_key.encrypt(b"byte data")
You can also encrypt data using private key object:
private_key.encrypt()
To decrypt data:
decrypted = private_key.decrypt(encrypted) # b"byte data"
Also supports chunk encryption/decryption:
with open("file", "rb") as input_file, open("file.out", "wb") as output_file:
for chunk in private_key.encrypt_chunks(input_file, 1024):
output_file.write(chunk)
To sign data:
data = b"byte data"
signature = private_key.sign(data)
To verify signature:
public_key.verify(signature, data) # True
Both private and public keys can be serialized in PEM encoded PKCS8 format:
serialized_key = private_key.serialize()
loaded_private_key = PrivateKEK.load(serialized_key)
Hybrid encryption
How it works?
-
Ecryption:
-
Data is encrypted via fresh generated symmetric key.
-
Symmetric key is encrypted via public asymmetric key.
-
-
Decryption:
-
Symmetric key is decrypted via private asymmetric key.
-
Data is decrypted via loaded symmetric key.
-
Encrypted data consists of:
Content | Length |
---|---|
Key version | 1 byte |
Key id | 8 bytes |
Encrypted symmetric key | Equal to key length (256-512 bytes) |
Data encrypted via symmetric key | Slightly larger than the length of original data and multiple of block length (<= len(original) + len(block)) |
License
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.