本文整理汇总了PHP中phpseclib\Crypt\RSA::sign方法的典型用法代码示例。如果您正苦于以下问题:PHP RSA::sign方法的具体用法?PHP RSA::sign怎么用?PHP RSA::sign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类phpseclib\Crypt\RSA
的用法示例。
在下文中一共展示了RSA::sign方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sign
/**
* Sign with RSASS-PSS + MGF1+SHA256
*
* @param string $message
* @param PrivateKey $rsaPrivateKey
* @return string
*/
public static function sign($message, PrivateKey $rsaPrivateKey)
{
static $rsa = null;
if (!$rsa) {
$rsa = new RSA();
$rsa->setSignatureMode(RSA::SIGNATURE_PSS);
$rsa->setMGFHash('sha256');
}
$rsa->loadKey($rsaPrivateKey->getKey());
return $rsa->sign($message);
}
示例2: createSignatureData
/**
* Creates the signature data
*
* @param array $hashes
* @param X509 $certificate
* @param RSA $privateKey
* @return string
*/
private function createSignatureData(array $hashes, X509 $certificate, RSA $privateKey)
{
ksort($hashes);
$privateKey->setSignatureMode(RSA::SIGNATURE_PSS);
$privateKey->setMGFHash('sha512');
$signature = $privateKey->sign(json_encode($hashes));
return ['hashes' => $hashes, 'signature' => base64_encode($signature), 'certificate' => $certificate->saveX509($certificate->currentCert)];
}
示例3: calculateSignature
/**
* Static method for quick calls to calculate a signature.
* @link https://developer.walmartapis.com/#authentication
* @param string $consumerId
* @param string $privateKey
* @param string $requestUrl
* @param string $requestMethod
* @param string|null $timestamp
* @return string
* @throws \Exception
*/
public static function calculateSignature($consumerId, $privateKey, $requestUrl, $requestMethod, $timestamp = null)
{
if (is_null($timestamp) || !is_numeric($timestamp)) {
$timestamp = self::getMilliseconds();
}
/**
* Append values into string for signing
*/
$message = $consumerId . "\n" . $requestUrl . "\n" . strtoupper($requestMethod) . "\n" . $timestamp . "\n";
/**
* Get RSA object for signing
*/
$rsa = new RSA();
$decodedPrivateKey = base64_decode($privateKey);
$rsa->setPrivateKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
$rsa->setPublicKeyFormat(RSA::PRIVATE_FORMAT_PKCS8);
/**
* Load private key
*/
if ($rsa->loadKey($decodedPrivateKey, RSA::PRIVATE_FORMAT_PKCS8)) {
/**
* Make sure we use SHA256 for signing
*/
$rsa->setHash('sha256');
$rsa->setSignatureMode(RSA::SIGNATURE_PKCS1);
$signed = $rsa->sign($message);
/**
* Return Base64 Encode generated signature
*/
return base64_encode($signed);
} else {
throw new \Exception("Unable to load private key", 1446780146);
}
}