创建 JWS 签名时我必须将 JOSE header 放在哪里?

Where do i have to put the JOSE header when creating JWS signature?

我必须创建 JWS 签名,JOSE header 必须如下所示:

{
  "alg": "HS256",
  "kid": "V3vEe66RJm85eD72",
  "b64": false,
  "http://openbanking.org.uk/iat": 1501497671,
  "http://openbanking.org.uk/iss": "C=UK, ST=England, L=London, O=Acme Ltd.",
  "crit": ["b64","http://openbanking.org.uk/iat","http://openbanking.org.uk/iss"]
}

我必须把这个 header 放在 jwt.io 网站的什么地方,或者有人知道其他创建 jws 签名的好网站吗? 问题是,当我使用文档提供的 header 类型更改 jwt.io 中默认存在的 header 时,它在底部的 jwt.io 中说“无效签名”,为什么?

您可以将 header 添加到 jwt.io 调试器右栏的“HEADER”部分。

然后您在“验证签名”下的字段中添加一个秘密并获得一个令牌。 您的 JOSE Header contains a crit 声明导致“无效签名”:

The "crit" (critical) Header Parameter indicates that extensions to this specification and/or [JWA] are being used that MUST be understood and processed. Its value is an array listing the Header Parameter names present in the JOSE Header that use those extensions. If any of the listed extension Header Parameters are not understood and supported by the recipient, then the JWS is invalid.

签名本身没问题,只是 crit 声明导致签名无效错误。一旦您的 crit 声明包含 非空 列表,验证就会在 jwt.io.

上失败

您可以验证生成的令牌

eyJhbGciOiJIUzI1NiIsImtpZCI6IlYzdkVlNjZSSm04NWVENzIiLCJiNjQiOmZhbHNlLCJodHRwOi8vb3BlbmJhbmtpbmcub3JnLnVrL2lhdCI6MTUwMTQ5NzY3MSwiaHR0cDovL29wZW5iYW5raW5nLm9yZy51ay9pc3MiOiJDPVVLLCBTVD1FbmdsYW5kLCBMPUxvbmRvbiwgTz1BY21lIEx0ZC4iLCJjcml0IjpbImI2NCIsImh0dHA6Ly9vcGVuYmFua2luZy5vcmcudWsvaWF0IiwiaHR0cDovL29wZW5iYW5raW5nLm9yZy51ay9pc3MiXX0.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIn0.QrI016I1j2kKE-cth3xr8O5DUOLOrL-biUfkuVZb_Xo

(用秘密“秘密”创建) 在 https://www.jsonwebtoken.io/ 上,看到它可以被验证。该网站似乎并不关心 crit header 并且仅根据哈希进行检查。 (注意:此网站在解码后未显示正确的 header 和令牌的有效负载)

一般来说,您不应该把这些在线工具看得太重。它们用于测试和教育目的,而不是作为生产工具。