#NEWLINE# def encrypt( message , keyPath ) : #NEWLINE# #INDENT# "\n    Encrypts a message given a path to a local file containing a key.\n\n    :param message: The message to be encrypted.\n    :param keyPath: A path to a file containing a 256-bit key (and nothing else).\n    :type message: str\n    :type keyPath: str\n    :rtype: str\n\n    A constant overhead is added to every encrypted message (for the nonce and MAC).\n    >>> import tempfile\n    >>> k = tempfile.mktemp()\n    >>> with open(k, 'w') as f:\n    ...     f.write(nacl.utils.random(SecretBox.KEY_SIZE))\n    >>> message = 'test'\n    >>> len(encrypt(message, k)) == overhead + len(message)\n    True\n    " #NEWLINE# with open ( keyPath ) as f : #NEWLINE# #INDENT# key = f . read ( ) #NEWLINE# #UNINDENT# if ( len ( key ) != SecretBox . KEY_SIZE ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Key is %d bytes, but must be exactly %d bytes' % ( len ( keyPath ) , SecretBox . KEY_SIZE ) ) ) #NEWLINE# #UNINDENT# sb = SecretBox ( key ) #NEWLINE# nonce = nacl . utils . random ( SecretBox . NONCE_SIZE ) #NEWLINE# assert ( len ( nonce ) == SecretBox . NONCE_SIZE ) #NEWLINE# return str ( sb . encrypt ( message , nonce ) )