#!/usr/bin/python # -*- coding:utf-8 -*- import base64 import time from cryptography.hazmat.primitives.asymmetric import rsa, padding from cryptography.hazmat.primitives import serialization, hashes def get_public_key_from_file(filepath): with open(filepath, "rb") as key_file: public_key = serialization.load_pem_public_key( key_file.read(), ) return public_key public_key = get_public_key_from_file('C:/Users/17217/Desktop/teamwk123/users/admin/public.pem') # 将明文进行RSA加密 from time import strftime import requests a = requests.post("http://127.0.0.1:5000/qr", files={"qr_pic": open("C:/Users/17217/Desktop/teamwk123/users/admin/test.png", "rb")}) ab = a.text.replace('ツー', '°') ab = ab.replace('窶イ', '′') ab = ab.replace('窶ウ', '″') print(ab) # b = r = requests.post("http://127.0.0.1:5000/match", data={"pattern": "df123qwerty"}) # print(b.text) # file = open('C:/Users/17217/Desktop/teamwk123/result.txt','w') # plaintext0 = a.text # plaintext = plaintext0.encode('utf-8') # ciphertext = public_key.encrypt( # plaintext, # padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA256()), algorithm=hashes.SHA256(), label=None), # ) # b64_str = base64.b64encode(ciphertext).decode() # file.write(b64_str) # file1 = open('log.txt','a') # file1.write("guard "+ab +" "+strftime("%Y-%m-%d-%H-%M-%S")+'\n') current_time = time.strftime("%Y-%m-%d-%H-%M-%S") with open('log.txt', 'a', encoding='utf-8') as file1: file1.write(f"guard {ab} {current_time}\n")