def encrypt(self, exported_key, file_name): print "name:", file_name if os.path.exists(file_name): print 'exist' cryptography.encrypt(exported_key, file_name) print "encrypted", file_name, 'with', exported_key else: print 'not exist'
def sender(self): pub_key = cryptography.get_key().publickey().exportKey(format='DER') self.soc.send(pub_key) signature = str(time.time()).encode('utf-8') self.soc.send(cryptography.sign_signature(signature)) while not self.encrypt_cipher: None self.soc.send(cryptography.encrypt(signature, self.encrypt_cipher)) while self.connected: if self.outgoing and self.encrypt_cipher: text = self.outgoing.pop().encode('utf-8') ciphertext = cryptography.encrypt(text, self.encrypt_cipher) self.soc.send(ciphertext)
def lock(self, key): # saves the changes made to the vault to an encrypted vault file # open file vault_path = self.vault_name + ".blvf" vault_file = open(vault_path, "w") # encrypt vault encrypted_vault = cryptography.encrypt( 'BioLockVault:' + self.to_string(), cryptography.hash_password(key)) # write to file and close it vault_file.write(encrypted_vault) vault_file.close()
def login(): try: data = request.json email = data['email'] password = data['password'] stayloggedin = data['stayloggedin'] new_line = email + ';' + cryptography.hash(email + password) user = filesystem.get(constants.USERS_FILE, new_line) if user == None: return json_response({ 'success': False, 'reason': 'Wrong email or password' }) response = make_response( json_response({ 'success': True, 'user': userhandler.parse_userdata(user) })) validuntil = int(time.time( )) + 2592000 if stayloggedin == True else int(time.time()) + 3600 response.set_cookie( 'token', cryptography.encrypt( json.dumps({ 'user': user, 'validuntil': validuntil })), max_age=None if stayloggedin == False else 2592000, expires=None if stayloggedin == False else datetime.fromtimestamp(validuntil)) return response except: return abort(400, 'Bad input')
import sys import getpass import cryptography import gosh password = gosh.cryptpass() enc = cryptography.encrypt(sys.stdin.buffer.read(), password) sys.stdout.buffer.write(enc)
import cryptography keys = cryptography.setup() print(keys) print("\n") m = "Mensagem de teste" print("Mensagem: " + m) m = cryptography.encrypt(keys[0], m) print("Mensagem criptografada: " + m) m = cryptography.decrypt(keys[1], m) print("Mensagem revertida: " + m) print("\n")
def embed(msg_file=MSG_FILE, password=[-1, 2.01, 3], image_file=IMAGE_FILE, channel=CHANNEL, plane=PLANE, scope=SCOPE, ID=BUFFER): """ Test usage: embed('msg.txt', [-1, 2.01, 3], 'image.tiff') embed('msg.txt', [-1, 2.01, 3], 'image.tiff', 'R', 0, 5, 64) """ #============================================================================== # Filtering inputs #============================================================================== try: open(image_file) and open(msg_file) except IOError: return None except AttributeError: return None try: float(password[0]) except TypeError: return None except ValueError: return None except AttributeError: return None if channel == 'r' or channel == 'R' or channel == '0' or channel == 0: channel = 'R' elif channel == 'g' or channel == 'G' or channel == '1' or channel == 1: channel = 'G' elif channel == 'b' or channel == 'B' or channel == '2' or channel == 2: channel = 'B' else: channel = 'R' #Set channel to RED in case of incorrect input try: plane = abs(int(plane)) if plane > 7: plane = 7 except ValueError: return None try: ID = abs(int(ID)) if ID < 4: ID = 4 if ID % 4 != 0: ID = 4 * (1 + ID / 4) except ValueError: return None try: scope = abs(int(scope)) if scope % 2 == 0: scope += 1 if scope > 9: scope = 9 except ValueError: return None try: imread(image_file) try: imread(msg_file) return None except IOError: image = imread(image_file) except IOError: try: image = imread(msg_file) image_file, msg_file = msg_file, image_file except IOError: return None #============================================================================== channel = validate(msg_file, image_file, channel) #Switch to optimum channel<= if channel is None: return None elif channel != CHANNEL: # print 'Replace ``Channel`` value in ``setup_file`` with '+channel from configurator import reconfigure as rcfg rcfg(setup_file, 'Channel', channel) #filename, Keyword, newValue # CHANNEL = channel #Updating value for cross function use: Not Working from numpy import shape rows, columns, channels = shape(image) from cryptography import encrypt encrypted_bitplane = encrypt(image_file, msg_file, password, channel, plane, scope, ID) if np.size(encrypted_bitplane) == rows * columns: output_image = maker(image, channel, plane, encrypted_bitplane) base = os.path.basename(image_file) name = os.path.splitext(base)[0] ext = os.path.splitext(base)[1] new_image_file = name + "_encoded" + ext imsave(new_image_file, output_image, format='tiff') else: return None
with open(args.text) as f: text = f.read() if args.action != 'crack': key = helpers.lower_if_required_by_lang(args.key, args.lang) text = helpers.lower_if_required_by_lang(text, args.lang) alphabet_file_name = args.alphabet if args.lang == 'custom' else os.path.join( BASE_ALPHABET_PATH, args.lang + '.txt') with open(alphabet_file_name) as f: alphabet = f.readline()[:-1] if args.action == 'crack': ord_alph_file_name = args.ord_alph if args.lang == 'custom' else os.path.join( BASE_ALPHABET_PATH, args.lang + '_ord.txt') with open(ord_alph_file_name) as f: ord_alph = f.readline()[:-1] text = helpers.remove_symbols_not_in_alphabet(text, alphabet) if args.action == 'encrypt': result = cryptography.encrypt(text, key, alphabet) elif args.action == 'decrypt': result = cryptography.decrypt(text, key, alphabet) elif args.action == 'crack': result = cryptography.crack(text, alphabet, ord_alph) with open(args.out, 'w') as f: f.write(result)