有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JWT签名验证失败,java到php

我和你们分享第一个密码

php代码 http://pastebin.com/b8TNfyzq第22行

JwtTester。JAVA http://pastebin.com/TsF0wsCX第22行

我在php服务器中编写的java代码中创建的令牌与该令牌不匹配。 虽然我不能在两边都验证同一把钥匙

我在用github。java代码中的com/jwtk/jjwt 还有github。php代码中的com/firebase/php jwt

与java代码和密钥中的数据相同,当我仅在PHP中创建令牌时,它由不同的令牌组成


共 (1) 个答案

  1. # 1 楼答案

    这是一个格式转换问题jjwt需要一个用base64编码的密钥,php jwt使用一个普通字符串

    Jjwt JwtBuilder

    JwtBuilder signWith(SignatureAlgorithm alg, String base64EncodedSecretKey);
    

    Php-jwt JWT

     /**
     * Decodes a JWT string into a PHP object.
     *
     * @param string        $jwt            The JWT
     * @param string|array  $key            The key, or map of keys.
     *                                      If the algorithm used is asymmetric, this is the public key
    public static function decode($jwt, $key, $allowed_algs = array()
    

    在调用JwtBuilder.signWith之前,在base64中对密钥进行编码

    builder.signWith(SignatureAlgorithm.HS256, 
                                   DatatypeConverter.printBase64Binary(key));