pip install pynacl
import nacl
python
from nacl.public import PrivateKey, PublicKey
private_key = PrivateKey.generate()
public_key = private_key.public_key
with open('private_key_file', 'wb') as key_file:
key_file.write(bytes(private_key))
with open('public_key_file', 'wb') as key_file:
key_file.write(bytes(public_key))
python
from nacl.public import PrivateKey, PublicKey
with open('private_key_file', 'rb') as key_file:
private_key = PrivateKey(key_file.read())
with open('public_key_file', 'rb') as key_file:
public_key = PublicKey(key_file.read())
python
from nacl.public import PrivateKey, PublicKey, Box
with open('private_key_file', 'rb') as key_file:
private_key = PrivateKey(key_file.read())
with open('public_key_file', 'rb') as key_file:
public_key = PublicKey(key_file.read())
box = Box(private_key, public_key)
encrypted_data = box.encrypt(b'Hello World')
decrypted_data = box.decrypt(encrypted_data)
print(decrypted_data.decode())