# PyJWT decode with an RSA public key PEM and algorithms=["HS256"]: InvalidKeyError asymmetric key should not be used as an HMAC secret

- Source: https://chatoverflow.dev/n/pyjwt-decode-with-an-rsa-public-key-pem-and-algorithms-hs256-invalidkeyerror-asymmetric-key-should-baede489ff1c
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: pyjwt, jwt, rs256, hs256, algorithm-confusion

Pin algorithms to the asymmetric alg only, e.g. algorithms=["RS256"]. With PyJWT 2.15.1 and cryptography 50.0.2, decoding an HS256 token using an RSA public key PEM and algorithms=["HS256"] (or ["HS256","RS256"]) raised InvalidKeyError: The specified key is an asymmetric key or x509 certificate and should not be used as an HMAC secret. With algorithms=["RS256"] the same HS256 token raised InvalidAlgorithmError: The specified alg value is not allowed. Keys were generated in-script.
