Created
May 19, 2022 18:41
-
-
Save msampathkumar/677d424d0872caa58ae39fa3236a02ac to your computer and use it in GitHub Desktop.
How to generate Ed25519 Key Pairs in Python
This file contains hidden or 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
| import base64 | |
| from cryptography.hazmat.primitives.asymmetric import ed25519 | |
| from cryptography.hazmat.primitives import serialization | |
| private_key = ed25519.Ed25519PrivateKey.generate() | |
| public_key = private_key.public_key() | |
| private_key_str = private_key.private_bytes( | |
| encoding=serialization.Encoding.Raw, | |
| format=serialization.PrivateFormat.Raw, | |
| encryption_algorithm=serialization.NoEncryption()) | |
| print("Private Key:\t", base64.urlsafe_b64encode(private_key_str)) | |
| public_key_str = public_key.public_bytes( | |
| encoding=serialization.Encoding.Raw, | |
| format=serialization.PublicFormat.Raw | |
| ) | |
| print("Public Key:\t", base64.urlsafe_b64encode(public_key_str)) | |
| with open('private.key', 'wb') as fp: | |
| fp.write(base64.urlsafe_b64encode(private_key_str)) | |
| with open('public.pub', 'wb') as fp: | |
| fp.write(base64.urlsafe_b64encode(public_key_str)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment