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.
55 lines
1.9 KiB
55 lines
1.9 KiB
import hashlib, base64
|
|
from tkinter import *
|
|
from tkinter import ttk
|
|
from pyDes import des, PAD_PKCS5, ECB
|
|
from Crypto.PublicKey import RSA
|
|
from Crypto.Hash import SHA256
|
|
from Crypto.Signature import PKCS1_v1_5
|
|
import rsa
|
|
from pyDes import des, CBC, PAD_PKCS5
|
|
from Crypto.Cipher import AES
|
|
import binascii
|
|
|
|
|
|
def panduan(root, op):
|
|
with open("encryptedkeyfile.bin", "rb") as f:
|
|
encryptedkeyfile = f.read()
|
|
with open("./Bprivkey.pem", "rb") as YY:
|
|
Bprivkey = YY.read()
|
|
privkey = rsa.PrivateKey.load_pkcs1(Bprivkey)
|
|
m = rsa.decrypt(encryptedkeyfile, privkey)
|
|
|
|
with open("encryptedfile.txt", "rb") as ff:
|
|
encryptedfile = ff.read()
|
|
secret_key = m
|
|
iv = secret_key
|
|
if op == "DES":
|
|
des_obj = des(secret_key, ECB, iv, pad=None, padmode=PAD_PKCS5)
|
|
decrypt_str = des_obj.decrypt(encryptedfile)
|
|
elif op == "AES_ECB":
|
|
aes_obj = AES.new(secret_key, mode=AES.MODE_ECB)
|
|
decrypt_str = aes_obj.decrypt(encryptedfile)
|
|
elif op == "AES_CBC":
|
|
aes = AES.new(secret_key, AES.MODE_CBC) # CBC模式下解密需要重新创建一个aes对象
|
|
decrypt_str = aes.decrypt(encryptedfile)
|
|
|
|
decrypt_str1 = decrypt_str.decode().rstrip("\0").encode()
|
|
|
|
decrypt_str2 = hashlib.sha256(decrypt_str1).hexdigest().encode("utf-8")
|
|
Apubkey = open("../client/Apubkey.pem", "rb").read().decode("utf-8")
|
|
key = RSA.importKey(Apubkey)
|
|
h = SHA256.new(decrypt_str2)
|
|
verifier = PKCS1_v1_5.new(key)
|
|
signature = open("sigfile.bin", "rb").read().decode()
|
|
if verifier.verify(h, base64.b64decode(signature)):
|
|
print("正确!")
|
|
zhaiyao = Label(
|
|
root, text="成功!", width=10, height=1
|
|
)
|
|
|
|
else:
|
|
zhaiyao = Label(
|
|
root, text="失败", width=10, height=1
|
|
)
|
|
zhaiyao.place(x=200,y=380,width=180,height=60)
|