export_key¶
-
classmethod
KeyManager.export_key(key: Union[cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKeyWithSerialization, cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKeyWithSerialization, cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PrivateKey, cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey, cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey, cryptography.hazmat.primitives.asymmetric.ed25519.Ed25519PublicKey], **kwargs) → bytes[source]¶ Export/serialize a given public/private key object as bytes.
Uses the default formatting arguments for the detected algorithm from
identify_algorithm(), but you can also force it to treat it as a certain algorithm by passingalgUses default formatting options by looking up the algorithm in
default_formatsUses the private key serialization arguments for the detected algorithm out of
generatorsExample:
>>> priv, pub = KeyManager.generate_keypair_raw('ed25519') >>> key = KeyManager.export_key(pub) >>> print(key.decode()) -----BEGIN PRIVATE KEY----- MC4CAQAwBQYDK2VwBCIEIOeLS2XOcQz11VUnzh6KIZaNtT10YfzHv779zjm95XSy -----END PRIVATE KEY-----
- Parameters
alg (str) – An algorithm name as a string, e.g.
rsaored25519key (combined_key_types) – An instance of a public/private key type listed in
combined_key_typesformat (Format) – Override some or all of the default format/encoding for the keys. Dict Keys: private_format,public_format,private_encoding,public_encoding
format – If passed a
Formatinstance, then this instance will be used for serialization instead of merging defaults fromdefault_formatsalg – Use this algorithm name e.g.
'rsa'instead of detecting usingidentify_algorithm()
- Return bytes key
The serialized key.