2017-02-09 95 views
0

和私鑰我有例子,如何簽署JWT鍵與私鑰,然後在PHP智威湯遜簽署與PHP

它與公衆一個解碼
$privKey = openssl_pkey_new(array('digest_alg' => 'sha256', 
     'private_key_bits' => 1024, 
     'private_key_type' => OPENSSL_KEYTYPE_RSA)); 
    $msg = JWT::encode('abc', $privKey, 'RS256'); 
    $pubKey = openssl_pkey_get_details($privKey); 
    $pubKey = $pubKey['key']; 
    $decoded = JWT::decode($msg, $pubKey, array('RS256')); 
    $this->assertEquals($decoded, 'abc'); 

,但在這裏產生,然後使用所產生的飛行關鍵,如果我需要使用已經生成的私鑰和公鑰,該怎麼辦?是否可以/足夠使用file_get_contents

更新

我發現openssl_pkey_get_privateopenssl_pkey_get_public我會嘗試使用此代碼使用它們。

回答

0

解決方案:

$private = openssl_pkey_get_private('file://key', 'keyphrase'); 
$token = \Firebase\JWT\JWT::encode('magic', $private, 'RS256'); 

$public = openssl_pkey_get_public('file://key.pub'); 
$data = \Firebase\JWT\JWT::decode($token, $public, ['RS256']);