Level up your Box knowledge with brand new learning paths on Box University. Visit training.box.com to get started

JWT with Python SDK giving "Could not unserialize key data."

Nouvelle publication

Commentaires

10 commentaires

  • uberscout

    I'm also running into this same issue.

    0
    Actions pour les commentaires Permalien
  • Murtza

      I am not sure why you are seeing this error, but according to this thread it might be an issue with the format of the private key you are using.

    0
    Actions pour les commentaires Permalien
  • uberscout

    I was looking at the Box SDK and it looks like it's in the JWTAuth object (jwt_auth.py) specifically:

     

    ```

    with open(rsa_private_key_file_sys_path) as key_file:
    self._rsa_private_key = serialization.load_pem_private_key(
    key_file.read(),
    password=rsa_private_key_passphrase,
    backend=default_backend(),
    )

    ```

    key_file.read() is passing it a string and it expects a bytes array (https://cryptography.io/en/latest/hazmat/primitives/asymmetric/serialization/#cryptography.hazmat.primitives.serialization.load_pem_private_key)

     

    I am just manually writing my JWT Auth but I believe the key_file.read() should be wrapped with bytes.

     

    ```

    with open(rsa_private_key_file_sys_path) as key_file:
    self._rsa_private_key = serialization.load_pem_private_key(
    bytes(key_file.read()),
    password=rsa_private_key_passphrase,
    backend=default_backend(),
    )

    ```

    0
    Actions pour les commentaires Permalien
  • uberscout

    Looks like this was fixed in an update. You should be able to do this now.

    0
    Actions pour les commentaires Permalien
  • DanEhrlich

    How do I fix this in Python 2.7?

    0
    Actions pour les commentaires Permalien
  • boobalganesan

    Which version was it fixed in? I am using 3.6 and still facing the issue.

    0
    Actions pour les commentaires Permalien
  • DimitrisT

    Same here...

    Anyone have had success?

    0
    Actions pour les commentaires Permalien
  • DimitrisT

    I was not decrypting my private key -- duh!

    0
    Actions pour les commentaires Permalien
  • SS90

    I don't know if this will help now or not but, you need to ensure that rsa_private_key_passphrase is in bytes and not string.

    So instead of -

    rsa_private_key_passphrase='XXXXXXX',

    use -

    rsa_private_key_passphrase=b'XXXXXXX', (for bytes)

    0
    Actions pour les commentaires Permalien
  • z07diac

    Did you solve this problem?

    0
    Actions pour les commentaires Permalien

Vous devez vous connecter pour laisser un commentaire.