我在Azure Portal免费订阅上获得访问令牌,标题为:
{
"typ": "JWT",
"alg": "RS256",
"x5t": "7_Zuf1tvkwLxYaHS3q6lUjUYIGw",
"kid": "7_Zuf1tvkwLxYaHS3q6lUjUYIGw"
}
Run Code Online (Sandbox Code Playgroud)
所以我从这里得到x5c 并放
-----开始证书----- MIIDBTCCAe ...... cNpO9oReBUsX -----结束证书-----
ze7xq1zGljQihJgcNpO9oReBUsX
Run Code Online (Sandbox Code Playgroud)
在https://jwt.io/中,签名已验证。
但是,当我尝试使用JDK1.8用jjwt和jose4j验证签名时,按照此 refrence中的步骤进行操作,我得到了下面的异常信息
PublicKey publicKey = keyFactory.generatePublic(keySpec);
java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException: ObjectIdentifier() -- data isn't an object ID (tag = -96)
at java.base/sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:204)
at java.base/java.security.KeyFactory.generatePublic(KeyFactory.java:352)
at com.ipscape.api.v1_0.external.other.JwtExample.decodeJwt(JwtExample.java:41)
at com.ipscape.api.v1_0.external.other.JwtExample.main(JwtExample.java:72)
Caused by: java.security.InvalidKeyException: IOException: ObjectIdentifier() -- data isn't an object ID (tag = -96)
at java.base/sun.security.x509.X509Key.decode(X509Key.java:396)
at java.base/sun.security.x509.X509Key.decode(X509Key.java:401)
at java.base/sun.security.rsa.RSAPublicKeyImpl.<init>(RSAPublicKeyImpl.java:86)
at java.base/sun.security.rsa.RSAKeyFactory.generatePublic(RSAKeyFactory.java:297)
at java.base/sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:200)
Run Code Online (Sandbox Code Playgroud)
使用jose4j的代码:
String publicKeyPEM …Run Code Online (Sandbox Code Playgroud)