new_contents: # -*- coding: utf-8 -*-
  
  # The MIT License (MIT)
  #
  # Copyright (c) 2015 Rafael Santos (rstogo@outlook.com)
  #
  # Permission is hereby granted, free of charge, to any person obtaining a copy
  # of this software and associated documentation files (the "Software"), to deal
  # in the Software without restriction, including without limitation the rights
  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  # copies of the Software, and to permit persons to whom the Software is
  # furnished to do so, subject to the following conditions:
  #
  # The above copyright notice and this permission notice shall be included in all
  # copies or substantial portions of the Software.
  #
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  # SOFTWARE.
  
  """Securily store sensitive information (mainly passwords).
  
  The key is generated using a password, plus the machine and user name,
  so the message can only be decrypted using the correct password, in the same
  machine, by the same user.
  
  """
  
  import hashlib
  import platform
  import os
  from Crypto.Cipher import AES
  from Crypto import Random
  from base64 import b64encode, b64decode
  
  
  def encrypt(key, data):
      key = '{}@{}@{}'.format(key, platform.node(), os.getlogin())
      print(key)
      key = hashlib.sha256(key.encode('utf-8')).digest()
  
      iv = Random.get_random_bytes(AES.block_size)
      aes = AES.new(key, AES.MODE_CFB, iv)
      crypted =  b64encode(iv) + b64encode(aes.encrypt(data))
  
      return crypted
  
  
  def decrypt(key, data):
      key = '{}@{}@{}'.format(key, platform.node(), os.getlogin())
      
      key = hashlib.sha256(key.encode('utf-8')).digest()
  
      iv = b64decode(data[:24])
      crypted = b64decode(data[24:])
  
      aes = AES.new(key, AES.MODE_CFB, iv)
      text = aes.decrypt(crypted)
      return text
  
  
  if __name__ == '__main__':
      crypted = encrypt('my password', 'my secret text')
      print(crypted)
  
      text = decrypt('my password', crypted)
      print(text)
  
subject: Create keyring.py