[精讚] [會員登入]
4439

[JAVA] JWS, JWT, JWE, JOSE是什麼?

[JAVA] JWS, JWT, JWE, JOSE是什麼?非常的複雜,儘量來搞清楚..

分享此文連結 //n.sfs.tw/10097

分享連結 [JAVA] JWS, JWT, JWE, JOSE是什麼?@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
2019-10-25 13:51:43 最後編修
2016-10-29 21:35:52 By 張○○
 

JWS (JSON Web Signatures) 定義在RFC7515[1]

   JSON Web Signature (JWS) represents content secured with digital
   signatures or Message Authentication Codes (MACs) using JSON-based
   data structures.

使用數位簽章 或 以Json為底的資料結構訊息認證碼[2] 來確保內容安全 的網頁簽章方式

JWS包函有:

   o  JOSE Header
   o  JWS Payload
   o  JWS Signature

其中JOSE是兩個部分的集合(二擇一或共存):

   o  JWS Protected Header
   o  JWS Unprotected Header

JOSE (JSON Object Signing and Encryption)[5] 是JSON物件簽章和編碼的方法

JWE (JSON Web Encryption)定義在RFC7516[3]中:

   JSON Web Encryption (JWE) represents encrypted content using JSON-
   based data structures [RFC7159].  The JWE cryptographic mechanisms
   encrypt and provide integrity protection for an arbitrary sequence of
   octets.

上面提到使用以Json為底的資料結構訊息認證碼加密後的內容就是 JWE

JWT ( JSON Web Token)定義在RFC7519[2]中:

   JSON Web Token (JWT) is a compact claims representation format
   intended for space constrained environments such as HTTP
   Authorization headers and URI query parameters.  JWTs encode claims
   to be transmitted as a JSON [RFC7159] object that is used as the
   payload of a JSON Web Signature (JWS) [JWS] structure or as the
   plaintext of a JSON Web Encryption (JWE) [JWE] structure, enabling
   the claims to be digitally signed or integrity protected with a
   Message Authentication Code (MAC) and/or encrypted.  JWTs are always
   represented using the JWS Compact Serialization or the JWE Compact
   Serialization.


JWT是緊湊宣告表示格式,適用於空間受限的環境,像HTTP的授權表頭 或 URI的query參數。JWT可放在JWS的載體或JWE的文字方式承載。

實作

在Nimbus JOSE+ JWT是有名的JAVA library [4],可以採用maven安裝,來看一下他的範例

// Create an HMAC-protected JWS object with some payload
JWSObject jwsObject = new JWSObject(new JWSHeader(JWSAlgorithm.HS256),
                                    new Payload("Hello world!"));
 
// We need a 256-bit key for HS256 which must be pre-shared
byte[] sharedKey = new byte[32];
new SecureRandom().nextBytes(sharedKey);
 
// Apply the HMAC to the JWS object
jwsObject.sign(new MACSigner(sharedKey));
 
// Output to URL-safe format
jwsObject.serialize();


這麼會搶鏡頭是怎樣?!

參考資料

[1] RFC7515 JWS https://tools.ietf.org/html/rfc7515
[2] RFC 7159 JWT RFC7159
[3] RFC7516 JWE https://tools.ietf.org/html/rfc7516
[4] Nimbus JOSE+JWT @connect2id
[5] JOSE https://datatracker.ietf.org/wg/jose/documents/
 

 

END

你可能感興趣的文章

如何在linux下執行java 原生的java應用程式可以使用簡單的方法在console下面寫出來,適合作簡單的應用

[NetBeans] 使用git複製別人的專案 NetBeans使用git複製別人的專案及版本控制

[JAVA] 撰寫驗證伺服器 #2 -- 安裝測試專案 僅僅只是做個記錄,這篇的參考效用非常微小

[JAVA] JWS, JWT, JWE, JOSE是什麼? [JAVA] JWS, JWT, JWE, JOSE是什麼?非常的複雜,儘量來搞清楚..

[JAVA] 撰寫驗證伺服器 #1 僅僅只是做個記錄,這篇的參考效用不大

[JAVA] 撰寫驗證伺服器 #3 -- 建立IDP伺服器 僅僅只是做個記錄,這篇的參考效用非常之微小

隨機好文

[jQuery] select 元件的取值及給值 html中的元件select,在jquery中要如何使用?

UTF-8 BOM (Byte Order Mark) 的問題 在 Michael Kaplan 那看到 Every character has a story #4: U+feff

NETCRAFT發現你的網站及作業系統 NETCRAFT可以發現你的網站及作業系統

對物品的感情 這個議題很奇怪,可是大部分的人都會有,物品是死的,壞了就淘汰,出新的就被替換。為何會有情感?

[Mysql] 資料型態int, float, double, text, char, varchar, blob大小 Mysql中資料型態int, float, text, char, varchar, blob大小