Psecio\Jwt\Jwt::sign PHP Метод

sign() публичный Метод

Generate the signature with the given data, key and algorithm
public sign ( string $signWith, string $key ) : string
$signWith string Data to sign hash with
$key string Key for signing
Результат string Generated signature hash
    public function sign($signWith, $key)
    {
        $hashType = $this->getHeader()->getAlgorithm();
        $hash = '\\Psecio\\Jwt\\HashMethod\\' . $hashType;
        if (class_exists($hash) === false) {
            throw new \InvalidArgumentException('Invalid hash type: ' . $hashType);
        }
        $hash = new $hash();
        if ($hash->getKeyType() === 'HMAC') {
            $signature = hash_hmac($hash->getAlgorithm(), $signWith, $key, true);
        } else {
            if ($hash->isValidKey($key) === false) {
                throw new \Psecio\Jwt\Exception\InvalidKeyException('Invalid key provided');
            }
            openssl_sign($signWith, $signature, $key, $hash->getAlgorithm());
        }
        if ($signature === false) {
            throw new \Psecio\Jwt\Exception\SignatureErrorException('Error signing with provided key');
        }
        return $signature;
    }