简体   繁体   English

如何生成与JWT.IO网站相同的签名?

[英]How to generate the same signature as the JWT.IO website does?

The JWT.IO website has a debugger for creating and validating JSON Web Token. JWT.IO网站有一个用于创建和验证JSON Web令牌的调试器。

When I copy and paste my secret string into the VERIFY SIGNATURE block, I can see that it generates a signature. 当我将我的秘密字符串复制并粘贴到VERIFY SIGNATURE块中时,我可以看到它生成一个签名。

JWT.IO

I scroll down the page a little bit and found the .NET solution implemented by Microsoft . 我向下滚动页面,发现Microsoft实现的.NET解决方案 After downloading, I add my unit test to generate the signature manually. 下载后,我添加单元测试以手动生成签名。

单元测试

However, the signature generated by the JWT.IO website is slightly different from the one generated by my unit test. 但是,JWT.IO网站生成的签名与我的单元测试生成的签名略有不同。

Secrect string: "THIS IS A SECRET STRING WHICH CAN BE SHARED BETWEEN THE SERVICES"
Unit test signature: "B0d57pcHoDiTDE/98dyrMx9HoFKGLOcM094eYBgJqHo="
JWT.IO    signature:  B0d57pcHoDiTDE_98dyrMx9HoFKGLOcM094eYBgJqHo

I notice that the JWT.IO signature string is URL encoding safe, but the unit test signature is not. 我注意到JWT.IO签名字符串是URL编码安全的,但单元测试签名不是。

How do I generate the same signature as the JWT.IO website does? 如何生成与JWT.IO网站相同的签名?

UPDATE UPDATE

The accepted answer below pointed me to the class Base64UrlEncoder . 下面接受的答案将我指向Base64UrlEncoder I have modified my unit test to generate the exact same signature as JWT.IO web site does: 我修改了我的单元测试以生成与JWT.IO网站完全相同的签名:

使用Base64UrlEncoder

@Believe2014 It seems that the jwt.io website does not have some options for specifying the base64 encoding with which way of URLEncoding to generate the same signature as your unit test. @ Believe2014似乎jwt.io网站没有一些选项来指定base64编码,使用哪种URLEncoding生成与单元测试相同的签名。

However, according to the section 4 & 5 of RFC 4648 , the differences between both signatures are using different characters for byte 62 & 63 and whether omits padding characters = . 但是,根据RFC 4648的第4和第5节,两个签名之间的差异对于字节6263使用不同的字符以及是否省略填充字符=

So for converting the signature generated by jwt.io into yours, just using / instead of _ , using + instead of - , and adding the padding characters = at the end of signature. 因此,为了将jwt.io生成的签名转换为你的签名,只需使用/而不是_ ,使用+而不是- ,并在签名结束时添加填充符=

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM