{"record":{"id":"03c2a6c5dae54c8f","repo":"jwtk/jjwt","slug":"unrecognized-rsa-or-rsassa-pss-key-algorithm-name","errorCode":null,"errorMessage":"Unrecognized RSA or RSASSA-PSS key algorithm name.","messagePattern":"Unrecognized RSA or RSASSA-PSS key algorithm name\\.","errorType":"exception","errorClass":"InvalidKeyException","httpStatus":null,"severity":"error","filePath":"impl/src/main/java/io/jsonwebtoken/impl/security/RsaSignatureAlgorithm.java","lineNumber":184,"sourceCode":"    @Override\n    public KeyPairBuilder keyPair() {\n        final String jcaName = this.algorithmParameterSpec != null ? PSS_JCA_NAME : \"RSA\";\n\n        //TODO: JDK 8 or later, for RSASSA-PSS, use the following instead of what is below:\n        //\n        // AlgorithmParameterSpec keyGenSpec = new RSAKeyGenParameterSpec(this.preferredKeyBitLength,\n        //     RSAKeyGenParameterSpec.F4, this.algorithmParameterSpec);\n        // return new DefaultKeyPairBuilder(jcaName, keyGenSpec).provider(getProvider()).random(Randoms.secureRandom());\n        //\n\n        return new DefaultKeyPairBuilder(jcaName, this.preferredKeyBitLength).random(Randoms.secureRandom());\n    }\n\n    @Override\n    protected void validateKey(Key key, boolean signing) {\n        super.validateKey(key, signing);\n        if (!isRsaAlgorithmName(key)) {\n            throw new InvalidKeyException(\"Unrecognized RSA or RSASSA-PSS key algorithm name.\");\n        }\n        int size = KeysBridge.findBitLength(key);\n        if (size < 0) return; // https://github.com/jwtk/jjwt/issues/68\n        if (size < MIN_KEY_BIT_LENGTH) {\n            String id = getId();\n            String section = id.startsWith(\"PS\") ? \"3.5\" : \"3.3\";\n            String msg = \"The RSA \" + keyType(signing) + \" key size (aka modulus bit length) is \" + size + \" bits \" +\n                    \"which is not secure enough for the \" + id + \" algorithm.  The JWT JWA Specification \" +\n                    \"(RFC 7518, Section \" + section + \") states that RSA keys MUST have a size >= \" +\n                    MIN_KEY_BIT_LENGTH + \" bits.  Consider using the Jwts.SIG.\" + id +\n                    \".keyPair() builder to create a KeyPair guaranteed to be secure enough for \" + id + \".  See \" +\n                    \"https://tools.ietf.org/html/rfc7518#section-\" + section + \" for more information.\";\n            throw new WeakKeyException(msg);\n        }\n    }\n\n    @Override\n    protected byte[] doDigest(final SecureRequest<InputStream, PrivateKey> request) {","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/jwtk/jjwt/blob/fb71496164c71442d08adec4571d9616ed5e1b8d/impl/src/main/java/io/jsonwebtoken/impl/security/RsaSignatureAlgorithm.java#L166-L202","documentation":"Thrown as InvalidKeyException by RsaSignatureAlgorithm.validateKey when the Key's algorithm name is not recognized as an RSA family algorithm ('RSA', RSASSA-PSS variants, etc.). jjwt only accepts keys whose JCA algorithm string identifies them as RSA keys for RS*/PS* signature algorithms.","triggerScenarios":"Passing a non-RSA Key (e.g. a SecretKey or EC key, or a key with an unusual/blank getAlgorithm() such as 'OID.1.2.840...' or provider-specific names) to sign with/verify with an RS256/RS384/RS512/PS256/PS384/PS512 algorithm.","commonSituations":"Mixing key types (using an HMAC secret with RS256); keys loaded via providers that report non-standard algorithm names (some Android/old JDK providers report OID-based names); loading keys with wrong KeyFactory algorithm.","solutions":["Use an RSAPublicKey/RSAPrivateKey with the RSA signature algorithm (check key instanceof java.security.interfaces.RSAPublicKey).","If the provider reports odd algorithm names, reload the key using KeyFactory.getInstance(\"RSA\") so getAlgorithm() returns 'RSA'.","Match the signature algorithm family to the key type (HS* for SecretKey, ES*/EC keys, RS*/PS* for RSA)."],"exampleFix":"// before\nSecretKey key = Keys.secretKeyFor(SignatureAlgorithm.HS256);\nJwts.builder().signWith(key, Jwts.SIG.RS256); // wrong key family\n// after\nKeyPair kp = Jwts.SIG.RS256.keyPair().build();\nJwts.builder().signWith(kp.getPrivate(), Jwts.SIG.RS256);","handlingStrategy":"type-guard","validationCode":"boolean isRsaKey(Key k) { return k instanceof RSAPublicKey || k instanceof RSAPrivateKey; }","typeGuard":"boolean isRsaAlgorithmNamed(Key k) { return k instanceof RSAPublicKey || k instanceof RSAPrivateKey; }","tryCatchPattern":"try { jwt = Jwts.parser().verifyWith((RSAPublicKey) key).build().parseSignedClaims(token); } catch (InvalidKeyException e) { throw new IllegalArgumentException(\"RS* algorithms require RSA keys\", e); }","preventionTips":["Match key family to algorithm: RS*/PS* -> RSA keys, ES* -> EC keys, HS* -> SecretKey.","Reload keys via KeyFactory.getInstance(\"RSA\") if providers report odd algorithm names.","Avoid passing raw SecretKey objects into RSA algorithm signers."],"tags":["rsa","key-validation","signature","key-type-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"fb71496164c71442d08adec4571d9616ed5e1b8d","analyzedAt":"2026-09-09T00:33:09.982Z","contentChangedAt":"2026-09-09T00:33:09.982Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}