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