#NEWLINE# def _create_rsa_key_pair( self , length , public_exponent = 65537 ) : #NEWLINE# #INDENT# '\n        Create an RSA key pair.\n\n        Args:\n            length(int): The length of the keys to be created. This value must\n                be compliant with the constraints of the provided algorithm.\n            public_exponent(int): The value of the public exponent needed to\n                generate the keys. Usually a small Fermat prime number.\n                Optional, defaults to 65537.\n\n        Returns:\n            dict: A dictionary containing the public key data, with the\n                following key/value fields:\n                * value - the bytes of the key\n                * format - a KeyFormatType enumeration for the bytes format\n                * public_exponent - the public exponent integer\n            dict: A dictionary containing the private key data, identical in\n                structure to the one above.\n\n        Raises:\n            CryptographicFailure: Raised when the key generation process\n                fails.\n        ' #NEWLINE# self . logger . info ( 'Generating an RSA key pair with length: {0}, and public_exponent: {1}' . format ( length , public_exponent ) ) #NEWLINE# try : #NEWLINE# #INDENT# private_key = rsa . generate_private_key ( public_exponent = public_exponent , key_size = length , backend = default_backend ( ) ) #NEWLINE# public_key = private_key . public_key ( ) #NEWLINE# private_bytes = private_key . private_bytes ( serialization . Encoding . DER , serialization . PrivateFormat . PKCS8 , serialization . NoEncryption ( ) ) #NEWLINE# public_bytes = public_key . public_bytes ( serialization . Encoding . DER , serialization . PublicFormat . PKCS1 ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# self . logger . exception ( e ) #NEWLINE# raise exceptions . CryptographicFailure ( 'An error occurred while generating the RSA key pair. See the server log for more information.' ) #NEWLINE# #UNINDENT# public_key = { #NEWLINE# #INDENT# 'value' : public_bytes , #NEWLINE# 'format' : enums . KeyFormatType . PKCS_1 , #NEWLINE# 'public_exponent' : private_bytes , #NEWLINE# #UNINDENT# } #NEWLINE# private_key = { #NEWLINE# #INDENT# 'value' : private_bytes , #NEWLINE# 'format' : enums . KeyFormatType . PKCS_8 , #NEWLINE# 'public_exponent' : public_exponent , #NEWLINE# #UNINDENT# } #NEWLINE# return ( public_key , private_key )