Created
November 30, 2019 00:38
-
-
Save gabrielfalcao/364c0179c63c431afcae2a48ffa4536d to your computer and use it in GitHub Desktop.
Ed25519 signing in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cryptography.hazmat.primitives.asymmetric.ed25519 import ( | |
Ed25519PrivateKey, | |
Ed25519PublicKey, | |
) | |
from cryptography.hazmat.primitives import serialization | |
private_key = Ed25519PrivateKey.generate() | |
public_key = private_key.public_key() | |
private_pem = private_key.private_bytes( | |
encoding=serialization.Encoding.Raw, | |
format=serialization.PrivateFormat.Raw, | |
encryption_algorithm=serialization.NoEncryption() | |
) | |
with open('private_key.pem', 'wb') as f: | |
f.write(private_pem) | |
public_pem = public_key.public_bytes( | |
encoding=serialization.Encoding.Raw, | |
format=serialization.PublicFormat.Raw, | |
) | |
with open('public_key.pem', 'wb') as f: | |
f.write(public_pem) | |
with open("private_key.pem", "rb") as key_file: | |
private_key = Ed25519PrivateKey.from_private_bytes(key_file.read()) | |
with open("public_key.pem", "rb") as key_file: | |
public_key = Ed25519PublicKey.from_public_bytes(key_file.read()) | |
print(private_key) | |
print(public_key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment