Skip to content

Issue when loading a key #2730

@njordr

Description

@njordr

Hi.

If I try to load a key with the following code:

from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.backends import default_backend
serialization.load_pem_private_key('test30.key', 'licupitinguanniancoffmat', default_backend())

I got the following error:
TypeError: initializer for ctype 'char[]' must be a bytes or list or tuple, not str

If I try with:
serialization.load_pem_private_key(open('test30.key', 'rb'), 'licupitinguanniancoffmat', default_backend())

I got:
TypeError: '_io.BufferedReader' object cannot be interpreted as an integer

If I try with:
serialization.load_pem_private_key(open('test30.key', 'rb').read(), 'licupitinguanniancoffmat', default_backend())

I got:
From cffi callback <function _pem_password_cb at 0x7f2f84e910d0>:
Traceback (most recent call last):
File "/usr/local/virtualenv/syseye/lib/python3.4/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 676, in _pem_password_cb
pw_buf[:len(ud.password)] = ud.password
TypeError: expected an object with a buffer interface

Could you please explain me how to import a private key?

Thanks,
Giovanni
test30.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions