Cryptography: serialization.NoEncryption not recognized as KeySerializationEncryption

Created on 1 Dec 2015  路  2Comments  路  Source: pyca/cryptography

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
)

Most helpful comment

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 :(

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BobbyGR picture BobbyGR  路  5Comments

darkn3rd picture darkn3rd  路  6Comments

webknjaz picture webknjaz  路  7Comments

wexi picture wexi  路  5Comments

trishankatdatadog picture trishankatdatadog  路  4Comments