def generate_ssh_keys(
cls, size=4096, passphrase=None, private_format=PrivateFormat.PKCS8,
public_format=PublicFormat.OpenSSH, private_encoding=Encoding.PEM,
public_encoding=Encoding.OpenSSH):
"""Generates a public and private rsa ssh key
Returns an SSHKeyResponse objects which has both the public and private
key as attributes
:param int size: RSA modulus length (must be a multiple of 256)
and >= 1024
:param str passphrase: The pass phrase to derive the encryption key
from
"""
encryption = (
BestAvailableEncryption(passphrase) if passphrase else
NoEncryption())
key = rsa.generate_private_key(
backend=default_backend(),
public_exponent=65537,
key_size=size)
return SSHKey(
public_key=key.public_key().public_bytes(
public_encoding, public_format),
private_key=key.private_bytes(
Encoding.PEM, private_format, encryption))
评论列表
文章目录