Oauth2-解析令牌始终引发异常
我正试图以这种方式解析令牌:Oauth2-解析令牌始终引发异常,oauth,Oauth,我正试图以这种方式解析令牌: Claims claims1 = Jwts.parser() .setSigningKey( publicKey) .parseClaimsJws( token); 但我总是有这样的例外: java.lang.IllegalArgumentException: Key bytes cannot be specified for RSA signatures. Pleas
Claims claims1 = Jwts.parser()
.setSigningKey( publicKey)
.parseClaimsJws( token);
但我总是有这样的例外:
java.lang.IllegalArgumentException: Key bytes cannot be specified for RSA signatures. Please specify a PublicKey or PrivateKey instance.
尽管如此,当我在中使用公钥和私钥尝试相同的令牌时,它会被验证。两个问题:
我假设您的
publicKey
是Base64编码字符串。
在这种情况下,您需要对其进行解码,并创建sun.security.rsa.RSAPublicKeyImpl
的实例:
byte[]decode=TextCodec.BASE64.decode(公钥);
Key Key=新的RSAPPublicKeyImpl(解码);
Claims claims1=Jwts.parser()
.设置点火钥匙(钥匙)
.parseClaimsJws(令牌);