2016-08-20 116 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));