从Python到PHP的JWS脚本

时间:2018-07-13 13:06:48

标签: java php python jwt json-web-signature

有人可以帮助我将其转换为PHP吗?我尝试使用namshi / jose,但每次都会创建随机密钥,这与我的python脚本不同。

我的Python脚本:

    from jose import jws
    import hashlib
    import base64

    privatekey = """-----BEGIN RSA PRIVATE KEY-----KEY-----END RSA PRIVATE KEY----   -"""

    payload = 'somepayload'
    payload_utf8 = payload.encode("utf-8")
    payload_sha1 = hashlib.sha1(payload_utf8).digest()
    payload_base64 = base64.b64encode(payload_sha1)

    payload_signed = jws.sign(payload_base64, privatekey, algorithm='RS256')
    print(payload_signed)

我尝试使用namshi / jose(https://github.com/namshi/jose/):

    $jws  = new SimpleJWS(array(
    'alg' => 'RS256'
    ));

    $payload = utf8_encode("somepayload");
    $payload = base64_encode(sha1($payload , true ) );  

    $jws->setPayload(array(
        'payload' => $payload,
    ));

    $privateKey = "-----BEGIN RSA PRIVATE KEY-----KEY-----END RSA PRIVATE KEY-----";
    echo $jws->sign($privateKey);

0 个答案:

没有答案