有人可以帮助我将其转换为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);