调试测试中

main
ps5antq2e 2 months ago
parent 7df46c9fbd
commit 8c3c8208a6

@ -12,7 +12,7 @@
# #
from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5 import QtCore, QtGui, QtWidgets
import sys import sys
from PyQt5.QtWidgets import QFileDialog,QMainWindow from PyQt5.QtWidgets import QFileDialog,QMainWindow,QMessageBox
from gmssl import sm4, func from gmssl import sm4, func
import json import json
import socket import socket
@ -86,12 +86,15 @@ class Ui_MainWindow(object):
self.mode="" self.mode=""
self.algorithm="" self.algorithm=""
self.encrypted_text="" self.encrypted_text=""
QMessageBox.information(MainWindow, "提示", "请选择自己的公钥")
path = QFileDialog.getOpenFileName()[0] path = QFileDialog.getOpenFileName()[0]
with open(path,"rb") as f: with open(path,"rb") as f:
self.public_key=crypto.load_publickey(crypto.FILETYPE_PEM,f.read()) self.public_key=crypto.load_publickey(crypto.FILETYPE_PEM,f.read())
QMessageBox.information(MainWindow, "提示", "请选择自己的私钥")
path = QFileDialog.getOpenFileName()[0] path = QFileDialog.getOpenFileName()[0]
with open(path,"rb") as f: with open(path,"rb") as f:
self.private_key=crypto.load_privatekey(crypto.FILETYPE_PEM,f.read()) self.private_key=crypto.load_privatekey(crypto.FILETYPE_PEM,f.read())
QMessageBox.information(MainWindow, "提示", "请选择对方的公钥")
path = QFileDialog.getOpenFileName()[0] path = QFileDialog.getOpenFileName()[0]
with open(path,"rb") as f: with open(path,"rb") as f:
self.public_key_other=crypto.load_publickey(crypto.FILETYPE_PEM,f.read()) self.public_key_other=crypto.load_publickey(crypto.FILETYPE_PEM,f.read())
@ -138,7 +141,7 @@ class Ui_MainWindow(object):
text = text + (b'\0' * add) text = text + (b'\0' * add)
encrypted_text = cryptor.encrypt(text) encrypted_text = cryptor.encrypt(text)
self.encrypted_text = b2a_hex(encrypted_text).decode("utf-8") self.encrypted_text = b2a_hex(encrypted_text).decode("utf-8")
self.textBrowser.append(encrypted_text+"\n") self.textBrowser.append(encrypted_text.decode())
elif self.mode=="CBC": elif self.mode=="CBC":
mode = AES.MODE_CBC mode = AES.MODE_CBC
cryptor = AES.new(self.key, mode, self.key)#iv = self.key cryptor = AES.new(self.key, mode, self.key)#iv = self.key
@ -149,7 +152,7 @@ class Ui_MainWindow(object):
text = text + (b'\0' * add) text = text + (b'\0' * add)
encrypted_text = cryptor.encrypt(text) encrypted_text = cryptor.encrypt(text)
self.encrypted_text = b2a_hex(encrypted_text).decode("utf-8") self.encrypted_text = b2a_hex(encrypted_text).decode("utf-8")
self.textBrowser.append(encrypted_text+"\n") self.textBrowser.append(encrypted_text.decode())
else: else:
self.textBrowser.append("mode error") self.textBrowser.append("mode error")
elif self.algorithm=="SM4": elif self.algorithm=="SM4":

Loading…
Cancel
Save