Created
March 20, 2018 13:07
-
-
Save davidp94/3b9ebafcfa41adaafca1f912f2554e66 to your computer and use it in GitHub Desktop.
Generate RSA 3072 bits public keys and private keys python with cryptography package and print them in PEM/PKCS format
This file contains 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
from cryptography.hazmat.primitives import serialization as crypto_serialization | |
from cryptography.hazmat.primitives.asymmetric import rsa | |
from cryptography.hazmat.backends import default_backend as crypto_default_backend | |
key = rsa.generate_private_key( | |
backend=crypto_default_backend(), | |
public_exponent=65537, | |
key_size=3072 | |
) | |
private_key = key.private_bytes( | |
crypto_serialization.Encoding.PEM, | |
crypto_serialization.PrivateFormat.PKCS8, | |
crypto_serialization.NoEncryption()) | |
public_key = key.public_key().public_bytes( | |
crypto_serialization.Encoding.PEM, | |
crypto_serialization.PublicFormat.SubjectPublicKeyInfo | |
) | |
print('{}\t{}'.format(public_key, private_key)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment