#!/usr/bin/env python # -*- coding:utf-8 -*- import os import json from base64 import b64encode from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5 def encrypt_pwd(password, public_key): rsa_key = RSA.importKey(public_key) encryptor = Cipher_pkcs1_v1_5.new(rsa_key) cipher = b64encode(encryptor.encrypt(password.encode('utf-8'))) return cipher.decode('utf-8') def open_image(image_file): if os.name == "nt": os.system('start ' + image_file) # for Windows else: if os.uname()[0] == "Linux": os.system("eog " + image_file) # for Linux else: os.system("open " + image_file) # for Mac def save_image(resp, image_file): with open(image_file, 'wb') as f: for chunk in resp.iter_content(chunk_size=1024): f.write(chunk) def parse_json(s): begin = s.find('{') end = s.rfind('}') + 1 return json.loads(s[begin:end])