久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用公鑰端點驗證 JWT 簽名

Verifying JWT Signature using public key endpoint(使用公鑰端點驗證 JWT 簽名)
本文介紹了使用公鑰端點驗證 JWT 簽名的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想驗證一些來自 Microsoft 的 JWT 的簽名.我正在使用 Spring-Boot、JJWT 庫和以下端點:https://login.microsoftonline.com/common/discovery/v2.0/keys

I'm wanting to verify the signature of some JWTs from Microsoft. I'm using Spring-Boot, the JJWT library and following endpoint: https://login.microsoftonline.com/common/discovery/v2.0/keys

端點返回一個 JSON 公鑰數組.這是數組中的一個示例.

The endpoint returns an array of JSON public keys. Here is one example from the array.

 {
            "kty": "RSA",
            "use": "sig",
            "kid": "9FXDpbfMFT2SvQuXh846YTwEIBw",
            "x5t": "9FXDpbfMFT2SvQuXh846YTwEIBw",
            "n": "kvt1VmR4nwkNM8jMU0wmj2gSS8NznbOt2pZI6Z7HQT_esF7W19GZR7Y72Xo1i5zXRDM9o3GeTIjBrnr3yy41Q_EaUQ7C-b-Hmg94Vy7EBZyBhi_mznz0dYWs2MIXwR86Nni9TmgTXvjgTPF2YGJoZt4TwcMFefW8rijCVyNrCBA0XspDouNJavvG0BEMXYigoThFjLRXS5U3h4BDfNZFZZS3dyliNOXfgRn2k7oITz8h_ueiPvmDRFh38AeQgx1cELhKWc3P5ugtttraSwgH7nP2NUguO9nCrHuL6TZ-KWpmRWZqwH-jYKFQVt3CDpzwNM6XJL-oHbl1x-gI3YYX5w",
            "e": "AQAB",
            "x5c": [
                "MIIDBTCCAe2gAwIBAgIQZSAeaqWig4BHC1ksmNNcgjANBgkqhkiG9w0BAQsFADAtMSswKQYDVQQDEyJhY2NvdW50cy5hY2Nlc3Njb250cm9sLndpbmRvd3MubmV0MB4XDTE3MDUwNjAwMDAwMFoXDTE5MDUwNzAwMDAwMFowLTErMCkGA1UEAxMiYWNjb3VudHMuYWNjZXNzY29udHJvbC53aW5kb3dzLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAJL7dVZkeJ8JDTPIzFNMJo9oEkvDc52zrdqWSOmex0E/3rBe1tfRmUe2O9l6NYuc10QzPaNxnkyIwa5698suNUPxGlEOwvm/h5oPeFcuxAWcgYYv5s589HWFrNjCF8EfOjZ4vU5oE1744EzxdmBiaGbeE8HDBXn1vK4owlcjawgQNF7KQ6LjSWr7xtARDF2IoKE4RYy0V0uVN4eAQ3zWRWWUt3cpYjTl34EZ9pO6CE8/If7noj75g0RYd/AHkIMdXBC4SlnNz+boLbba2ksIB+5z9jVILjvZwqx7i+k2filqZkVmasB/o2ChUFbdwg6c8DTOlyS/qB25dcfoCN2GF+cCAwEAAaMhMB8wHQYDVR0OBBYEFGKpXQNrF5IoxS6bL4F92+gxOJlIMA0GCSqGSIb3DQEBCwUAA4IBAQA3HgW5SoHlvvQVxqqi+mtscDZLhNfe13iG/nx8Er5il82b79RVydNs+f9sYxc4T4ctnrZu7x5e7jInJedNdAlrPorBdw+SfvKJsmiNndXugMew1FlcQTQVIFDCbziaJav8rKyMxPfeKkc1aixbajWZkKg6OPmmJn2ceTocbn8PMQy20xNvcWUwgF5FZZIuPqu6feOLJcUIYw+0JFZ265xka30QXpmytcIxajIzpD4PRdCIBuVSqgXacAs4t4+w+OhnosD72yvXck8M4GwX1j+vcuyw0yhDGNMmqsHWP7H3jnJiGDrKhhdVyplzDhTfv2Whbv/dIDn+meLE3yyC5yGL"
            ],
            "issuer": "https://login.microsoftonline.com/{tenantid}/v2.0"
        }

在 JJWT 中,我實現了 SigningKeyResolver 接口,我需要返回一個 RSAPublicKey 實例來進行驗證.我遇到的問題是從 JSON 正確創建該密鑰.

In JJWT I've implemented the SigningKeyResolver interface and I am required to return an instance of RSAPublicKey to do the verification. The issue I'm having is creating that Key correctly from the JSON.

我是否從模數和指數開始?

Do I start with the Modulus and Exponent?

BigInteger modulus = new BigInteger(1, Base64.decodeBase64(jsonKey.getN()));
BigInteger exponent = new BigInteger(1, Base64.decodeBase64(jsonKey.getE()));
publicKey = KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(modulus, exponent));

我是否從 x5c 開始,生成一個 X509Certificate 對象并從那里提取 PublicKey?

Do I start with the x5c, generate an X509Certificate object and pull the PublicKey from there?

CertificateFactory factory = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) factory
          .generateCertificate(new ByteArrayInputStream(
           DatatypeConverter.parseBase64Binary(jsonKey.getX5c())));
publicKey = (RSAPublicKey)cert.getPublicKey();

這兩種方法都被證明是徒勞的.

Both approaches have proved fruitless.

如果我從模數和指數生成 RSAPublicKey,我應該能夠打印 Base64Binary 編碼的密鑰以匹配 x5c 屬性嗎?也許這不是我應該驗證的方式.

If I generated the RSAPublicKey from the modulus and exponent should I be able to print the Base64Binary encoded key to match the x5c property? Maybe that's not how I should be validating.

我可能誤解了如何使用它.

與往常一樣,我們也歡迎任何文檔.

As always, any documentation is appreciated as well.

推薦答案

x5c 包含認證鏈.鏈的第一個證書必須與 JWK 中其他值表示的密鑰值匹配,在本例中為 ne,因此從 x5c[0]ne 構建的必須完全相同

x5c contains the certification chain. The first certificate of the chain must match with the key value represented by the other values in the JWK, in this case n and e, therefore the public key extracted from x5c[0] and the one built with n and e must be exactly the same

JWK 值在 base64url 中編碼,而不是在 base64 中.改變

JWK values are encoded in base64url, not in base64. Change

BigInteger modulus = new BigInteger(1, Base64.decodeBase64(jsonKey.getN()));
BigInteger exponent = new BigInteger(1, Base64.decodeBase64(jsonKey.getE()));

BigInteger modulus = new BigInteger(1, Base64.getUrlDecoder().decode(jsonKey.getN()));
BigInteger exponent = new BigInteger(1, Base64.getUrlDecoder().decode(jsonKey.getE()));

這篇關于使用公鑰端點驗證 JWT 簽名的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 日韩精品一区二区三区在线 | 欧美一区二区免费 | 男人的天堂久久 | 日屁视频 | 亚洲日韩欧美一区二区在线 | 一区二区三区欧美在线 | 男女羞羞视频免费 | 欧美精品99 | 日韩在线不卡 | 综合网视频 | 国产ts一区| 国产精品爱久久久久久久 | 国产三级电影网站 | 久久精品国产一区二区电影 | 成人影院在线视频 | 最新国产精品 | 亚洲一区二区在线免费观看 | 久久国产欧美日韩精品 | 一本岛道一二三不卡区 | 久久久久久a | 久久99网站 | 99热热热热 | 在线亚洲电影 | 天天色天天色 | 91av视频| 毛片一级片 | 自拍视频一区二区三区 | 国产福利91精品一区二区三区 | a在线观看 | 超碰在线影院 | 欧美成人一区二免费视频软件 | 久久新| 欧美日韩一二区 | 日本粉嫩一区二区三区视频 | 欧美天堂在线观看 | 国产高清视频一区 | 国产高清精品网站 | 欧美成ee人免费视频 | 久久精品国产亚洲a | h视频在线看 | 欧美一级片免费看 |