Skip to content

Instantly share code, notes, and snippets.

@msampathkumar
Created May 19, 2022 18:41
Show Gist options
  • Save msampathkumar/677d424d0872caa58ae39fa3236a02ac to your computer and use it in GitHub Desktop.
Save msampathkumar/677d424d0872caa58ae39fa3236a02ac to your computer and use it in GitHub Desktop.

Revisions

  1. msampathkumar created this gist May 19, 2022.
    24 changes: 24 additions & 0 deletions Python_ed25519.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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))