[Python] opening privatekey from string rather than file in python 3?

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I found some python code to read a private key from a file to connect to Snowflake and it works fine

    with open("rsa_key_1.p8", "rb") as key:
    p_key= serialization.load_pem_private_key(
    key.read(),
    password=None,
    backend=default_backend()
    )


    However, I would like to use the actual string rather than reading from a file, so I tried replacing key.read() by the actual string

    with open("rsa_key_1.p8", "rb") as key:
    p_key= serialization.load_pem_private_key(
    'MIIE...rZ+x8ZcfhhLj+lyWLhDfA8feg/vYlV+gLDKsZfQLN9JDRMGgffN3EE7vM9WBO/msB8fpo5g==',
    password=None,
    backend=default_backend()
    )


    But this gives me this error


    TypeError: from_buffer() cannot return the address of a unicode object
    ​

    Could this be a generic python error?

    Continue reading...

Compartilhe esta Página