JwtCoder.php
protected function sign($msg, $key, $method = 'HS256')
  {
    if (empty(self::$methods[$method])) {
      throw new \DomainException('Algorithm not supported');
    }
    list($function, $algo) = self::$methods[$method];
    
    switch($function) 
    {
      case 'hash_hmac': return hash_hmac($algo, $msg, $key, true);
        
      case 'openssl':
        $signature = '';
        $success = openssl_sign($msg, $signature, $key, $algo);
        if(!$success) {
          throw new \DomainException("OpenSSL unable to sign data");
        }
        return $signature;
    }
    return ''; // Should not get here
  }
protected function sign($msg, $key, $method = 'HS256')
  {
    if (empty(self::$methods[$method])) {
      throw new \DomainException('Algorithm not supported');
    }
    list($function, $algo) = self::$methods[$method];
    
    switch($function) 
    {
      case 'hash_hmac': return hash_hmac($algo, $msg, $key, true);
        
      case 'openssl':
        $signature = '';
        $success = openssl_sign($msg, $signature, $key, $algo);
        if(!$success) {
          throw new \DomainException("OpenSSL unable to sign data");
        }
        return $signature;
    }
    return ''; // Should not get here
  }
protected function sign ( $ msg , $ key , $ method = 'HS256' ) { if ( empty ( self :: $ methods [ $ method ] ) ) { throw new \ DomainException ( 'Algorithm not supported' ) ; } list ( $ function , $ algo ) = self :: $ methods [ $ method ] ; switch ( $ function ) { case 'hash_hmac' : return hash_hmac ( $ algo , $ msg , $ key , true ) ; case 'openssl' : $ signature = '' ; $ success = openssl_sign ( $ msg , $ signature , $ key , $ algo ) ; if ( ! $ success ) { throw new \ DomainException ( "OpenSSL unable to sign data" ) ; } return $ signature ; } return '' ; // Should not get here }
Sign a string with a given key and algorithm.

@param string $msg          The message to sign
@param string|resource $key The secret key
@param string $method       The signing algorithm. Supported algorithms
are 'HS256', 'HS384', 'HS512' and 'RS256'

@return string           An encrypted message
@throws \DomainException Unsupported algorithm was specified
Sign a string with a given key and algorithm .