javascript - 我怎么知道 json 网络 token 是否被篡改

标签 javascript json encryption jwt

有什么方法可以知道 JSON Web Token 是否被篡改过。比如body改了或者过期时间改了等等。

我已经尝试阅读 JWT 的 RFC,但该语言对我来说有点高级。

最佳答案

来自 Wikipedia :

JWTs generally have three parts: a header, a payload, and a signature. The header identifies which algorithm is used to generate the signature, and looks something like this:

header = '{"alg":"HS256","typ":"JWT"}'

The signature is calculated by base64url encoding the header and payload and concatenating them with a period as a separator:

To put it all together, the signature is base64url encoded.

所以...您获取 token 的签名,从 base64 对其进行解码,从 header 中获取加密算法并生成 base64 编码 header + '.' 的签名。 + base64 编码的有效载荷。如果您计算出的签名与您收到的签名匹配,那么很可能没有人篡改 JWT。

关于javascript - 我怎么知道 json 网络 token 是否被篡改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45564339/

相关文章:

javascript - 如何在 Javascript 上动态交叉交叉合并那些 JSON 数组?

ssl - HTTPS应用层数据如何解密?

json - com.jayway.jsonpath.JsonPath 找不到 key

apache - 如何使用 ECDHE-RSA-AES128-GCM-SHA256 密码通过 Openssl 生成 PEM 文件

php - 如何加密和解密PHP字符串?

javascript - 循环 ID 并添加额外的 attr()

javascript - ReactJS 中的 Proxy 组件是什么?

javascript - SVG 可聚焦属性不起作用

javascript - 如何在通过 load() 加载内容后更改或附加到 URL

json - Newtonsoft.JSON 使用 GUID 序列化\反序列化数据表