Php 警告:openssl_sign()要求参数4很长
我正在尝试为使用apple mapkit js生成JWT。我发现了一个开源代码,可以生成在本地机器上运行良好的令牌。然而,当我上传到我的服务器时,我得到了以下错误 警告:Php 警告:openssl_sign()要求参数4很长,php,openssl,jwt,php-openssl,Php,Openssl,Jwt,Php Openssl,我正在尝试为使用apple mapkit js生成JWT。我发现了一个开源代码,可以生成在本地机器上运行良好的令牌。然而,当我上传到我的服务器时,我得到了以下错误 警告:openssl\u sign()预期参数4较长 导致问题的线路是 if (!openssl_sign($payload, $result, $key, OPENSSL_ALGO_SHA256)); <?php /** * Copyright 2018 Includable *
openssl\u sign()
预期参数4较长
导致问题的线路是
if (!openssl_sign($payload, $result, $key, OPENSSL_ALGO_SHA256));
<?php
/**
* Copyright 2018 Includable
* Created by Thomas Schoffelen
*/
namespace Mapkit;
/**
* Class JWT
*
* @package Mapkit
*/
class JWT
{
/**
* Generates a JWT token that can be used for MapKit JS or MusicKit authorization.
*
* @param string $private_key Contents of, or path to, private key file
* @param string $key_id Key ID provided by Apple
* @param string $team_id Apple Developer Team Identifier
* @param string $origin Optionally limit header origin
* @param integer $expiry The expiry timeout in seconds (defaults to 3600)
* @return string|false
*/
public static function getToken($private_key, $key_id, $team_id, $origin = null, $expiry = 3600)
{
$header = [
'alg' => 'ES256',
'typ' => 'JWT',
'kid' => $key_id
];
$body = [
'iss' => $team_id,
'iat' => time(),
'exp' => time() + $expiry
];
if ($origin) {
$body['origin'] = $origin;
}
$payload = self::encode(json_encode($header)) . '.' . self::encode(json_encode($body));
if (!$key = openssl_pkey_get_private($private_key)) {
return false;
}
if (!openssl_sign($payload, $result, $key, OPENSSL_ALGO_SHA256)) { //this is the line that's cause a problem
return false;
}
return $payload . '.' . self::encode($result);
}
/**
* URL-safe base64 encoding.
*
* @param string $data
* @return string
*/
private static function encode($data)
{
$encoded = strtr(base64_encode($data), '+/', '-_');
return rtrim($encoded, '=');
}
}
if(!openssl_-sign($payload,$result,$key,openssl_-algou_-SHA256));
您的服务器上运行的是哪个PHP版本?我运行的是5.2.14,但我尝试了5.3、7.1、7.3,但都不起作用。我的版本与我在本地运行的版本相同。服务器上似乎未启用openssl扩展。参考本文,我从php.info中对extension=php_openssl.dll进行了注释,但仍然得到相同的错误。在phpinfo中,我看到了启用openssl支持的openssl版本openssl 0.9.8o 2010年6月1日