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(令牌);