You are here

public static function JWT::sign in Auth0 Single Sign On 8.2

Sign a string with a given key and algorithm.

Parameters

string $msg The message to sign:

string|resource $key The secret key:

string $alg The signing algorithm.: Supported algorithms are 'ES256', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'

Return value

string An encrypted message

Throws

DomainException Unsupported algorithm was specified

1 call to JWT::sign()
JWT::encode in vendor/firebase/php-jwt/src/JWT.php
Converts and signs a PHP object or array into a JWT string.

File

vendor/firebase/php-jwt/src/JWT.php, line 198

Class

JWT
JSON Web Token implementation, based on this spec: https://tools.ietf.org/html/rfc7519

Namespace

Firebase\JWT

Code

public static function sign($msg, $key, $alg = 'HS256') {
  if (empty(static::$supported_algs[$alg])) {
    throw new DomainException('Algorithm not supported');
  }
  list($function, $algorithm) = static::$supported_algs[$alg];
  switch ($function) {
    case 'hash_hmac':
      return \hash_hmac($algorithm, $msg, $key, true);
    case 'openssl':
      $signature = '';
      $success = \openssl_sign($msg, $signature, $key, $algorithm);
      if (!$success) {
        throw new DomainException("OpenSSL unable to sign data");
      }
      else {
        if ($alg === 'ES256') {
          $signature = self::signatureFromDER($signature, 256);
        }
        return $signature;
      }
  }
}