dongxu198714 2016-08-20 15:15
浏览 927

JWT签名验证失败,java到php

I share with you the first codes

php codes http://pastebin.com/b8TNfyzq line 22

JwtTester.java http://pastebin.com/TsF0wsCX line 22

Token created in java code I wrote in php server does not match the token. Although I can not verify the same key on both sides

I'm using github.com/jwtk/jjwt in java code and github.com/firebase/php-jwt in php codes

same with java code and data in key , consists of different token when I create the token in only PHP

  • 写回答

2条回答 默认 最新

  • duai4379 2016-08-20 16:58
    关注

    Is a format conversion issue. jjwt requires a key encoded in base64 and php-jwt uses a plain string

    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()
    

    Encode your key in base64 before invoking JwtBuilder.signWith

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

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试