public static function signMessage($message, $key, $hashKey = '')
    {
        # Test the message and key for string validity.
        Helpers::isString($message, 'Encryption', 'signMessage');
        Helpers::isString($key, 'Encryption', 'signMessage');
        Helpers::isString($hashKey, 'Encryption', 'signMessage');

        # Create a special hashed key for encryption.
        $key = Hash::hash($key, $hashKey, Constants::AUTH_KEYBYTES);

        # Generate a MAC for the message.
        $mac = \Sodium\crypto_auth($message, $key);

        return base64_encode(json_encode([
            'mac' => Helpers::bin2hex($mac),
            'msg' => $message,
        ]));
    }
public static function signMessage($message, $key, $hashKey = '')
    {
        # Test the message and key for string validity.
        Helpers::isString($message, 'Encryption', 'signMessage');
        Helpers::isString($key, 'Encryption', 'signMessage');
        Helpers::isString($hashKey, 'Encryption', 'signMessage');

        # Create a special hashed key for encryption.
        $key = Hash::hash($key, $hashKey, Constants::AUTH_KEYBYTES);

        # Generate a MAC for the message.
        $mac = \Sodium\crypto_auth($message, $key);

        return base64_encode(json_encode([
            'mac' => Helpers::bin2hex($mac),
            'msg' => $message,
        ]));
    }
public static function signMessage ( $ message , $ key , $ hashKey = '' ) { # Test the message and key for string validity. Helpers :: isString ( $ message , 'Encryption' , 'signMessage' ) ; Helpers :: isString ( $ key , 'Encryption' , 'signMessage' ) ; Helpers :: isString ( $ hashKey , 'Encryption' , 'signMessage' ) ; # Create a special hashed key for encryption. $ key = Hash :: hash ( $ key , $ hashKey , Constants :: AUTH_KEYBYTES ) ; # Generate a MAC for the message. $ mac = \ Sodium \ crypto_auth ( $ message , $ key ) ; return base64_encode ( json_encode ( [ 'mac' => Helpers :: bin2hex ( $ mac ) , 'msg' => $ message , ] ) ) ; }
Returns a signed message to the client for authentication.

@param string $message The message to be signed.
@param string $key The signing key used with the message.
@param string $hashKey The key to hash the key with.
@return string A JSON string including the signing information and message.
@throws Exceptions\InvalidTypeException
@throws Exceptions\OutOfRangeException
Returns a signed message to the client for authentication .