Skip to content

Instantly share code, notes, and snippets.

@r-sajal
Created June 24, 2022 12:48
Show Gist options
  • Save r-sajal/9a7af63418215acd58fc0345c7ffa90c to your computer and use it in GitHub Desktop.
Save r-sajal/9a7af63418215acd58fc0345c7ffa90c to your computer and use it in GitHub Desktop.
Support for blog on medum
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.backends import default_backend
try:
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=int(5e3),
backend=default_backend()
)
private_pem = private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption()
)
with open('private_key.pem', 'wb') as f:
f.write(private_pem)
public_key = private_key.public_key()
public_pem = public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo
)
with open('public_key.pem', 'wb') as f:
f.write(public_pem)
print("\nSuccessfully created Public and Private Key\n")
except Exception as e:
print("\nFailure\n")
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment