Welcome to the new Box Support website. Check out all the details here on what’s changed.

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

New post

Comments

10 comments

  • uberscout

    I'm also running into this same issue.

    0
    Comment actions Permalink
  • 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
    Comment actions Permalink
  • 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
    Comment actions Permalink
  • uberscout

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

    0
    Comment actions Permalink
  • DanEhrlich

    How do I fix this in Python 2.7?

    0
    Comment actions Permalink
  • boobalganesan

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

    0
    Comment actions Permalink
  • DimitrisT

    Same here...

    Anyone have had success?

    0
    Comment actions Permalink
  • DimitrisT

    I was not decrypting my private key -- duh!

    0
    Comment actions Permalink
  • 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
    Comment actions Permalink
  • z07diac

    Did you solve this problem?

    0
    Comment actions Permalink

Please sign in to leave a comment.