Created
August 2, 2022 17:26
-
-
Save vlaci/9ec8aceda46fa2e3324fd9822ba328b3 to your computer and use it in GitHub Desktop.
Generate x25519 certificate
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
#!/usr/bin/env python | |
import datetime as dt | |
from cryptography import x509 | |
from cryptography.hazmat.backends.openssl import backend | |
from cryptography.hazmat.primitives import serialization | |
from cryptography.hazmat.primitives.asymmetric import ed25519, x25519 | |
from cryptography.x509.oid import NameOID | |
issuer_private_key = ed25519.Ed25519PrivateKey.generate() | |
subject_private_key = x25519.X25519PrivateKey.generate() | |
not_valid_before = dt.datetime(2022, 1, 1, 12, 1) | |
not_valid_after = dt.datetime(2040, 12, 31, 8, 30) | |
builder = ( | |
x509.CertificateBuilder() | |
.serial_number(777) | |
.issuer_name(x509.Name([x509.NameAttribute(NameOID.COUNTRY_NAME, "HU")])) | |
.subject_name(x509.Name([x509.NameAttribute(NameOID.COUNTRY_NAME, "HU")])) | |
.public_key(subject_private_key.public_key()) | |
.not_valid_before(not_valid_before) | |
.not_valid_after(not_valid_after) | |
) | |
cert = builder.sign(issuer_private_key, None, backend) | |
print(cert.public_bytes(serialization.Encoding.PEM).decode()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment