Skip to content

Instantly share code, notes, and snippets.

@thebluesnevrdie
Created September 20, 2023 01:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebluesnevrdie/f1522bf5305d561f42dac25ff398f2e9 to your computer and use it in GitHub Desktop.
Save thebluesnevrdie/f1522bf5305d561f42dac25ff398f2e9 to your computer and use it in GitHub Desktop.
Generate ed25515 OpenSSH keys with Python3 cryptography library
#! /usr/bin/env python3
from cryptography.hazmat.primitives.asymmetric import rsa, ed25519
from cryptography.hazmat.primitives import serialization, hashes
private_key = ed25519.Ed25519PrivateKey.generate()
public_key = private_key.public_key()
our_private = private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.OpenSSH,
encryption_algorithm=serialization.NoEncryption(),
)
our_public = public_key.public_bytes(
encoding=serialization.Encoding.OpenSSH, format=serialization.PublicFormat.OpenSSH
)
print(our_private.decode("utf-8"))
print("-----BEGIN OPENSSH PUBLIC KEY-----")
print(our_public.decode("utf-8"))
print("-----END OPENSSH PUBLIC KEY-----")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment