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.
teamwk123/users/admin/decode.py

38 lines
1.2 KiB

1 month ago
#!/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('D:/99/ui_ref/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("D:/99/ui_ref/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('D:/99/ui_ref/users/admin/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')