2016-08-20 229 views
0

我跟大家分享的第一个码JWT签名验证失败,JAVA到PHP

PHP代码 http://pastebin.com/b8TNfyzq线22

JwtTester.java http://pastebin.com/TsF0wsCX线在Java代码中创建22

令牌我写的在PHP服务器不符合令牌。 虽然我无法验证两边

我在PHP代码使用github.com/jwtk/jjwt在Java代码中 和github.com/firebase/php-jwt

一样使用相同的密钥java代码和密钥中的数据,包括不同的令牌,当我创建令牌时只有PHP

+0

请勿链接代码。复制代码 – pedrofb

回答

0

是格式转换问题。 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() 

进行编码以base64密钥调用JwtBuilder.signWith

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