Encrypt symmetric keys with RSA.
Project description
Easy RSA
Encrypt symmetric keys with RSA.
Hierarchy
easyrsa
'---- EasyRSA()
|---- gen_key_pair()
|---- encrypt()
|---- decrypt()
|---- sign()
|---- verify()
'---- max_msg_size()
Example
python
from easyrsa import *
# generate a key pair
kp = EasyRSA(bits=1024).gen_key_pair()
print(kp)
# {"public_key": b"...", "private_key": b"..."}
# maximum message size in bytes encrypted with a n bits RSA key
print(EasyRSA(public_key=kp["public_key"]).max_msg_size())
# 86
print(EasyRSA(private_key=kp["private_key"]).max_msg_size())
# 86
# encryption and decryption
# note that each EasyRSA object must bind only one operation
from base64 import b64encode
symmetric_key = "abc" or b"abc"*100 or b64encode(b"abc")
encrypted_key = EasyRSA(public_key=kp["public_key"]).encrypt(symmetric_key)
print(encrypted_key)
# ...
print(symmetric_key == EasyRSA(private_key=kp["private_key"]).decrypt(encrypted_key))
# True
# sign and verify
msg = "encrypted"
s = EasyRSA(private_key=kp["private_key"]).sign(msg)
# and then somewhere you receive the msg and s
print(EasyRSA(public_key=kp["public_key"]).verify(msg, s))
# True
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
easyrsa-0.8.0.tar.gz
(15.6 kB
view hashes)
Built Distribution
easyrsa-0.8.0-py3-none-any.whl
(15.5 kB
view hashes)