apple-music-token-generator icon indicating copy to clipboard operation
apple-music-token-generator copied to clipboard

ValueError: Could not deserialize key data.

Open YayongLi opened this issue 5 years ago • 4 comments

run python music_token.py result Traceback (most recent call last): File "music_token.py", line 36, in token = jwt.encode(payload, secret, algorithm=alg, headers=headers) File "/Library/Python/2.7/site-packages/jwt/api_jwt.py", line 65, in encode json_payload, key, algorithm, headers, json_encoder File "/Library/Python/2.7/site-packages/jwt/api_jws.py", line 113, in encode key = alg_obj.prepare_key(key) File "/Library/Python/2.7/site-packages/jwt/algorithms.py", line 351, in prepare_key key = load_pem_private_key(key, password=None, backend=default_backend()) File "/Library/Python/2.7/site-packages/cryptography/hazmat/primitives/serialization.py", line 20, in load_pem_private_key return backend.load_pem_private_key(data, password) File "/Library/Python/2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1016, in load_pem_private_key password, File "/Library/Python/2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1235, in _load_key self._handle_key_loading_error() File "/Library/Python/2.7/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1293, in _handle_key_loading_error raise ValueError("Could not deserialize key data.") ValueError: Could not deserialize key data.

YayongLi avatar Jan 05 '19 08:01 YayongLi

Im getting the same thing. I used this script in the past and it worked, but not now.

kaodygh avatar Jan 09 '19 06:01 kaodygh

I tested it with alg: HS256, it works.

The problem for me is when I use ES256 which is whats required for Apple Musickit api authentication.

kaodygh avatar Jan 09 '19 07:01 kaodygh

I was facing the same issue and fixed it by reading the .p8 file instead of pasting the key into the script. secret = open('YourAuthFileNameHere.p8', 'rb').read() The rest remains the same.

Cyatos avatar Feb 19 '19 17:02 Cyatos

You need change secret, need 3 or 4 lines.

like this: https://github.com/pyca/cryptography/issues/4417#issuecomment-416942613

-----BEGIN PRIVATE KEY-----
MIGTAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwIBAQQgsegINAr5xcE48BiD
yfXjsfQmEk1ReGtD7bSuKsKx04CgCgYIKoZIzj0DAQehRANCAASauMCp36D8FOF1
5OGI1+fe5oeRoCbY5yGQ2Jk0Gi9P92ksyvC8LK7JDqtzKfEf18UsScYc+NWffEtt
v413G73q
-----END PRIVATE KEY-----

hhgz9527 avatar Feb 10 '20 14:02 hhgz9527