You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.2 KiB
38 lines
1.2 KiB
#!/usr/bin/python
|
|
|
|
# -*- coding:utf-8 -*-
|
|
import base64
|
|
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/english/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/english/users/admin/qrcode.png", "rb")})
|
|
print(a.text)
|
|
b = r = requests.post("http://127.0.0.1:5000/match", data={"pattern": "df123qwerty"})
|
|
print(b.text)
|
|
file = open('C:/Users/17217/Desktop/english/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 "+a.text +" "+strftime("%Y-%m-%d-%H-%M-%S")+'\n')
|
|
|