I am trying to create and serialize an RSA private key without a passphrase.
I am getting the following error when using serializtion.NoEncryption as the encryption_algorithm in private_bytes:
File "space_pki.py", line 99, in serialize_private_key
encryption_algorithm=serialization.NoEncryption
File "/usr/local/lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/rsa.py", line 566, in private_bytes
self._rsa_cdata
File "/usr/local/lib/python2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1926, in _private_key_bytes
"Encryption algorithm must be a KeySerializationEncryption "
TypeError: Encryption algorithm must be a KeySerializationEncryption instance
Here is the code I am using to serialize an RSA private key key_object I created using rsa.generate_private_key
private_key = key_object.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.TraditionalOpenSSL,
encryption_algorithm=serialization.NoEncryption
)
NoEncryption is actually a class, so the call needs to be serialization.NoEncryption().
It's a class because BestAvailableEncryption takes an argument, but since format and encoding are enums this is somewhat confusing :(
thank you so much. worked perfect!
Most helpful comment
NoEncryptionis actually a class, so the call needs to beserialization.NoEncryption().It's a class because
BestAvailableEncryptiontakes an argument, but since format and encoding are enums this is somewhat confusing :(