Exemple #1
0
 private static function sign($input, $key, $algo)
 {
     switch ($algo) {
         case 'HS256':
             return hash_hmac('sha256', $input, $key, true);
         case 'HS384':
             return hash_hmac('sha384', $input, $key, true);
         case 'HS512':
             return hash_hmac('sha512', $input, $key, true);
         case 'RS256':
             return JWT::generateRSASignature($input, $key, OPENSSL_ALGO_SHA256);
         case 'RS384':
             return JWT::generateRSASignature($input, $key, OPENSSL_ALGO_SHA384);
         case 'RS512':
             return JWT::generateRSASignature($input, $key, OPENSSL_ALGO_SHA512);
         default:
             throw new Exception("Unsupported or invalid signing algorithm.");
     }
 }