我一直在用 Java 编写一个 RESTful 服务。这是我到目前为止所理解的(如果我错了,请纠正我):
token 授权是使用 JSON Web token (JWT) 完成的,它包含三个部分: header 、有效负载和 key (在客户端和服务器之间共享)。
我理解了这个概念,并在阅读 JWT 时偶然发现了 JSON Web Signature (JWS)。
JWS 也是一个类似于 JWT 的编码实体,具有 header 、有效负载和共享 key 。
问题: JWT和JWS这两个概念有什么区别?如果它们在技术上相似,那么它们的实现有什么区别?
这是我第一次使用基于 token 的身份验证,所以我可能完全误解了这个概念。
附:我在浏览 this website 上的示例时了解了 JWS。 .
最佳答案
JWT 实际上使用 JWS 作为其签名,来自 spec's abstract :
JSON Web Token (JWT) is a compact, URL-safe means of representing claims to be transferred between two parties. The claims in a JWT are encoded as a JavaScript Object Notation (JSON) object that is used as the payload of a JSON Web Signature (JWS) structure or as the plaintext of a JSON Web Encryption (JWE) structure, enabling the claims to be digitally signed or MACed and/or encrypted.
因此,JWT 是一个以 JSON 对象作为有效负载的 JWS 结构。已经定义了一些可选键(或声明),例如 iss
、aud
、exp
等。
这也意味着它的完整性保护不仅限于共享 secret ,还可以使用公钥/私钥加密。
关于rest - JSON Web 签名 (JWS) 和 JSON Web token (JWT) 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27640930/