Jose\Util\RSA::sign PHP Method

sign() public static method

Create a signature.
public static sign ( RSAKey $key, string $message, string $hash ) : string
$key Jose\KeyConverter\RSAKey
$message string
$hash string
return string
    public static function sign(RSAKey $key, $message, $hash)
    {
        Assertion::string($message);
        Assertion::string($hash);
        Assertion::inArray($hash, ['sha256', 'sha384', 'sha512']);
        $em = self::encodeEMSAPSS($message, 8 * $key->getModulusLength() - 1, Hash::$hash());
        Assertion::string($em);
        $message = self::convertOctetStringToInteger($em);
        $signature = self::getRSASP1($key, $message);
        Assertion::isInstanceOf($signature, BigInteger::class);
        return self::convertIntegerToOctetString($signature, $key->getModulusLength());
    }

Usage Example

Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function sign(JWKInterface $key, $input)
 {
     $this->checkKey($key);
     Assertion::true($key->has('d'), 'The key is not a private key');
     $priv = new RSAKey($key);
     if ($this->getSignatureMethod() === self::SIGNATURE_PSS) {
         $signature = JoseRSA::sign($priv, $input, $this->getAlgorithm());
         $result = is_string($signature);
     } else {
         $result = openssl_sign($input, $signature, $priv->toPEM(), $this->getAlgorithm());
     }
     Assertion::true($result, 'An error occurred during the creation of the signature');
     return $signature;
 }