public static function encryptMessage($message, $key, $hashKey = '')
    {
        // Test the key for string validity.
        Helpers::isString($message, 'Encryption', 'encryptMessage');
        Helpers::isString($key, 'Encryption', 'encryptMessage');
        Helpers::isString($hashKey, 'Encryption', 'encryptMessage');
        // Create a special hashed key for encryption.
        $key = Hash::hash($key, $hashKey, Constants::SECRETBOX_KEYBYTES);
        // Generate a nonce for the communication.
        $nonce = Entropy::generateNonce();
        // Serialize and encrypt the message object
        $ciphertext = \Sodium\crypto_secretbox(serialize($message), $nonce, $key);
        $nonce = base64_encode($nonce);
        $ciphertext = base64_encode($ciphertext);
        $json = json_encode(compact('nonce', 'ciphertext'));
        if (! is_string($json)) {
            throw new Exceptions\EncryptionException('Failed to encrypt message using key');
        }
        return base64_encode($json);
    }