GitBook——统一接口认证解决方案
目前创新互联公司已为1000多家的企业提供了网站建设、域名、虚拟主机、网站运营、企业网站设计、抚顺县网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。JsonWebToken关于JsonWebToken的专业名词解释:
JsonWebToken主体分为三个部分:header、payload、signature
unsecured JWT结果示例:
eyJhbGciOiJub25lIn0.
eyJqdGkiOiJkZWJhNzhiZDZiNTI0ZTA2OWE4MmZjZTJlNzdmOTU2MSIsImlzcyI6Ik1hdGVNYXN0ZXIiLCJzdWIiOiLmnInmlYjotJ_ovb3mtYvor5UiLCJhdWQiOiJhdWRpZW5jZSIsImV4cCI6MTY3MDExNzIzMywibmJmIjoxNjcwMDMwODkzLCJpYXQiOjE2NzAwMzA4MzN9.
{"alg": "HS256",
"typ": "JWT",
"cty": ""
}
{"jti": "4a9813f957b84dda8091510402e7c33d",
"iss": "MateMaster",
"sub": "有效负载测试",
"aud": "audience",
"exp": 1670054958,
"nbf": 1669968618,
"iat": 1669968558
}
JWSJWS(Signed JWT)compact序列化主要生成流程:
结果示例
eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.
eyJpc3MiOiJtYXRlbWFzdGVyIiwic3ViIjoiandzIiwiYXVkIjoiYXVkaWVuY2UiLCJleHAiOjE2NzAwMzQ4NjEsImlhdCI6MTY3MDAzNDgwMSwibmJmIjoxNjcwMDM0ODAxLCJqdGkiOiIzNTA3M2FhYmMxMmU0ZDUzOTBkNGNjOGFlYzVhNmVlYyJ9.
pKhj-QPDszduhet_SZW6BfsLX0n88D__YvIHvfj87OSitCRq1ybb7Bc3ClZZfhf_ewgrhVUL4d4WK0JuCkl0gA
难点:
JWS JSON序列化
JWS JSON 序列化形式(多个签名)
{"payload": "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogIm h0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ",
"signatures": [
{"protected": "eyJhbGciOiJSUzI1NiJ9",
"header": {"kid": "2010-12-29"
},
"signature": "cC4hiUPoj9Eetdgtv3hF80EGrhuB__dzERat0XF9g2VtQgr9PJbu3XOiZj5RZmh7AA uHIm4Bh-0Qc_lF5YKt_O8W2Fp5jujGbds9uJdbF9CUAr7t1dnZcAcQjbKBYNX4BAyn RFdiuB--f_nZLgrnbyTyWzO5vRK5h6xBArLIARNPvkSjtQBMHlb1L07Qe7K0GarZRmB _eSN9383LcOLn6_dO--xi12jzDwusC-eOkHWEsqtFZESc6BfI7noOPqvhJ1phCnvWh6 IeYI2w9QOYEUipUTI8np6LbgGY9Fs98rqVt5AXLIhWkWywlVmtVrBp0igcN_IoypGlU PQGe77Rw"
},
{"protected": "eyJhbGciOiJFUzI1NiJ9",
"header": {"kid": "e9bc097a-ce51-4036-9562-d2ade882db0d"
},
"signature": "DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFCgfTjDx w5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q"
}
]
}
扁平化JWS JSON 序列化形式(单个签名)
{"payload": "eyJpc3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQog Imh0dHA6Ly9leGFtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ",
"protected": "eyJhbGciOiJFUzI1NiJ9",
"header": {"kid": "e9bc097a-ce51-4036-9562-d2ade882db0d"
},
"signature": "DtEhU3ljbEg8L38VWAfUAqOyKAM6-Xx-F4GawxaepmXFC gfTjDxw5djxLa8ISlSApmWQxfKTUJqPP3-Kg6NU1Q"
}
JSON 序列化与 compact序列化的区别:
JWS JSON字段含义
payload:base64编码的JWT负载字符串
protected:base64编码的JWS头部字符串,包含的声明受到签名保护
signatures:签名数组,header:不受签名保护的header,在unprotected header中是必须的,在protected中是可选的,signature:base64编码的JWS签名字符串
重点知识:
在JWS中,Share SecretKey,各方都可以验证和生成令牌。在公钥/私钥中,只有私钥可以验证、生成令牌,公钥只可以验证令牌,不能用于生成令牌
从生产者与消费者角度理解JWS
JWE(Encrypted JWT)compact序列化主要生成流程:
JWE(Encrypted JWT)compact序列化组成部分:
base64(header)
base64(encryptedKey) [step 2,3]
base64(initializationVector) [step 4]
base64(cipherText) [step 6]
base64(authenticationTag) [step 6]
eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2In0.
Y2DxdVnvuDwo5vutvvPg4PpGQKFmRxWoDUCtfs58Gv5rJ4J1RkSOUQ.
-Iu2VusgO_w0uWrn0JWx3Q.
krW8miBqh5x3dZ6ktf0C_A.
HHYK0TxHth2949NDPpwTsw
重点知识:
在JWE中,Share SecretKey,各方都可以加密解密令牌。在对称加密中,只有公钥可以加密数据,私钥解密
从生产者与消费者角度理解JWE
JWK的出现旨在,为不同加密密钥提供一个统一的格式标准
JWK样例
{"kty": "EC",
"crv": "P-256",
"x": "MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4",
"y": "4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM",
"d": "870MB6gfuTJ4HtUnUvYMyJpr5eUZNP4Bk43bVdj3eAE",
"use": "enc",
"kid": "1"
}
持续更新中…………
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧