public static 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");
} else {
return $signature;
}
}
}