code: def encrypt(message, keyPath):
      
      with open(keyPath, 'rb') as f:
          key = f.read()
      if len(key) != SecretBox.KEY_SIZE:
          raise ValueError("Key is %d bytes, but must be exactly %d bytes" % (len(key),
                                                                              SecretBox.KEY_SIZE))
      sb = SecretBox(key)
      # We generate the nonce using secure random bits. For long enough
      # nonce size, the chance of a random nonce collision becomes
      # *much* smaller than the chance of a subtle coding error causing
      # a nonce reuse. Currently the nonce size is 192 bits--the chance
      # of a collision is astronomically low. (This approach is
      # recommended in the libsodium documentation.)
      nonce = nacl.utils.random(SecretBox.NONCE_SIZE)
      assert len(nonce) == SecretBox.NONCE_SIZE
      return bytes(sb.encrypt(message, nonce))
docs: Encrypts a message given a path to a local file containing a key.
  
      :param message: The message to be encrypted.
      :param keyPath: A path to a file containing a 256-bit key (and nothing else).
      :type message: bytes
      :type keyPath: str
      :rtype: bytes
  
      A constant overhead is added to every encrypted message (for the nonce and MAC).
      >>> import tempfile
      >>> k = tempfile.mktemp()
      >>> with open(k, 'wb') as f:
      ...     _ = f.write(nacl.utils.random(SecretBox.KEY_SIZE))
      >>> message = 'test'.encode('utf-8')
      >>> len(encrypt(message, k)) == overhead + len(message)
      True
      >>> import os
      >>> os.remove(k)