有什么方法可以知道 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/