[精讚] [會員登入]
3951

[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

你可能感興趣的文章

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

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

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

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

在Centos7 下安裝 Wildfly10 wildfly以前叫JBoss,2014.11.20改名叫Wildfly,起始版本是Wildfly8,現在已經出到Wil

[Wildfly10] 發佈war檔 deploy war file onto wildfly10

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

[MAC] 截取螢幕畫面的方法 截取螢幕畫面的方法,在MAC中叫作螢幕快照,英文是screenshot

[jQuery] 利用load()來達成ajax的寫法 jQuery中利用load()來達成ajax的寫法,也有人稱他是假的ajax,作法就是..

HP SAS硬碟leds燈號說明 HP SAS硬碟leds燈號(hp g7/g6系統適用)說明

為什麼要買長達二十年的保單? 為什麼要買長達二十年的保單?找一個可以說服我買二十年保單的理由。

SELinux 常用指令和檔案 在Redhat系列中,Centos5以後加入了selinux,他並沒有這麼可怕,不必每次看到Selinux ,就想把他