-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
344 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Form implementation generated from reading ui file 'UI.ui' | ||
# | ||
# Created by: PyQt5 UI code generator 5.15.4 | ||
# | ||
# WARNING: Any manual changes made to this file will be lost when pyuic5 is | ||
# run again. Do not edit this file unless you know what you are doing. | ||
|
||
|
||
from PyQt5 import QtCore, QtGui, QtWidgets | ||
|
||
|
||
class Ui_MainWindow(object): | ||
def setupUi(self, MainWindow): | ||
MainWindow.setObjectName("MainWindow") | ||
MainWindow.resize(804, 421) | ||
self.centralwidget = QtWidgets.QWidget(MainWindow) | ||
self.centralwidget.setObjectName("centralwidget") | ||
self.gridLayout_4 = QtWidgets.QGridLayout(self.centralwidget) | ||
self.gridLayout_4.setObjectName("gridLayout_4") | ||
self.gridLayout_3 = QtWidgets.QGridLayout() | ||
self.gridLayout_3.setObjectName("gridLayout_3") | ||
self.gridLayout = QtWidgets.QGridLayout() | ||
self.gridLayout.setObjectName("gridLayout") | ||
self.label = QtWidgets.QLabel(self.centralwidget) | ||
self.label.setObjectName("label") | ||
self.gridLayout.addWidget(self.label, 0, 0, 1, 1) | ||
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget) | ||
self.lineEdit.setObjectName("lineEdit") | ||
self.gridLayout.addWidget(self.lineEdit, 0, 1, 1, 1) | ||
self.label_2 = QtWidgets.QLabel(self.centralwidget) | ||
self.label_2.setObjectName("label_2") | ||
self.gridLayout.addWidget(self.label_2, 0, 2, 1, 1) | ||
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget) | ||
self.lineEdit_2.setObjectName("lineEdit_2") | ||
self.gridLayout.addWidget(self.lineEdit_2, 0, 3, 1, 1) | ||
self.gridLayout_3.addLayout(self.gridLayout, 0, 0, 1, 1) | ||
self.gridLayout_2 = QtWidgets.QGridLayout() | ||
self.gridLayout_2.setObjectName("gridLayout_2") | ||
self.label_4 = QtWidgets.QLabel(self.centralwidget) | ||
self.label_4.setObjectName("label_4") | ||
self.gridLayout_2.addWidget(self.label_4, 0, 0, 1, 1) | ||
self.pushButton = QtWidgets.QPushButton(self.centralwidget) | ||
self.pushButton.setObjectName("pushButton") | ||
self.gridLayout_2.addWidget(self.pushButton, 1, 1, 1, 1) | ||
self.textEdit_2 = QtWidgets.QTextEdit(self.centralwidget) | ||
self.textEdit_2.setObjectName("textEdit_2") | ||
self.gridLayout_2.addWidget(self.textEdit_2, 1, 2, 9, 1) | ||
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget) | ||
self.pushButton_2.setObjectName("pushButton_2") | ||
self.gridLayout_2.addWidget(self.pushButton_2, 2, 1, 1, 1) | ||
self.label_3 = QtWidgets.QLabel(self.centralwidget) | ||
self.label_3.setObjectName("label_3") | ||
self.gridLayout_2.addWidget(self.label_3, 9, 1, 1, 1) | ||
self.textEdit = QtWidgets.QTextEdit(self.centralwidget) | ||
self.textEdit.setObjectName("textEdit") | ||
self.gridLayout_2.addWidget(self.textEdit, 1, 0, 9, 1) | ||
self.label_5 = QtWidgets.QLabel(self.centralwidget) | ||
self.label_5.setObjectName("label_5") | ||
self.gridLayout_2.addWidget(self.label_5, 0, 2, 1, 1) | ||
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget) | ||
self.pushButton_5.setObjectName("pushButton_5") | ||
self.gridLayout_2.addWidget(self.pushButton_5, 6, 1, 1, 1) | ||
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget) | ||
self.pushButton_4.setObjectName("pushButton_4") | ||
self.gridLayout_2.addWidget(self.pushButton_4, 5, 1, 1, 1) | ||
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget) | ||
self.pushButton_3.setObjectName("pushButton_3") | ||
self.gridLayout_2.addWidget(self.pushButton_3, 8, 1, 1, 1) | ||
self.gridLayout_3.addLayout(self.gridLayout_2, 1, 0, 1, 1) | ||
self.gridLayout_4.addLayout(self.gridLayout_3, 0, 0, 1, 1) | ||
MainWindow.setCentralWidget(self.centralwidget) | ||
self.menubar = QtWidgets.QMenuBar(MainWindow) | ||
self.menubar.setGeometry(QtCore.QRect(0, 0, 804, 26)) | ||
self.menubar.setObjectName("menubar") | ||
MainWindow.setMenuBar(self.menubar) | ||
self.statusbar = QtWidgets.QStatusBar(MainWindow) | ||
self.statusbar.setObjectName("statusbar") | ||
MainWindow.setStatusBar(self.statusbar) | ||
|
||
self.retranslateUi(MainWindow) | ||
QtCore.QMetaObject.connectSlotsByName(MainWindow) | ||
|
||
def retranslateUi(self, MainWindow): | ||
_translate = QtCore.QCoreApplication.translate | ||
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) | ||
self.label.setText(_translate("MainWindow", "SessionKey")) | ||
self.label_2.setText(_translate("MainWindow", "iv")) | ||
self.label_4.setText(_translate("MainWindow", "未加密内容")) | ||
self.pushButton.setText(_translate("MainWindow", "加密->")) | ||
self.pushButton_2.setText(_translate("MainWindow", "<-解密")) | ||
self.label_3.setText(_translate("MainWindow", "昨天输入原始内容\n" | ||
",需要替换的位置\n" | ||
"用%%标记。右边则\n" | ||
"输入字典,点击批\n" | ||
"量生成后会导出到\n" | ||
"txt文件")) | ||
self.label_5.setText(_translate("MainWindow", "加密内容")) | ||
self.pushButton_5.setText(_translate("MainWindow", "url解码")) | ||
self.pushButton_4.setText(_translate("MainWindow", "url编码")) | ||
self.pushButton_3.setText(_translate("MainWindow", "批量加密")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import binascii | ||
import base64 | ||
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes | ||
from cryptography.hazmat.backends import default_backend | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
|
||
def pad(data, block_size): | ||
padding = block_size - len(data) % block_size | ||
return data + padding * bytes([padding]) | ||
|
||
|
||
def encrypt_data(decrypted_data, iv, session_key): | ||
if session_key == "": | ||
return "Please enter key!" | ||
if iv == "": | ||
return "Please enter iv!" | ||
if decrypted_data == "": | ||
return "Please enter original data!" | ||
|
||
try: | ||
base64.decodestring(bytes(session_key, 'utf-8')) | ||
except binascii.Error: | ||
return "key no correct base64" | ||
try: | ||
base64.decodestring(bytes(iv, 'utf-8')) | ||
except binascii.Error: | ||
return "iv no correct base64" | ||
|
||
try: | ||
aes_iv = base64.b64decode(iv) | ||
aes_cipher = decrypted_data | ||
aes_key = base64.b64decode(session_key) | ||
|
||
cipher = Cipher(algorithms.AES(aes_key), modes.CBC(aes_iv), backend=default_backend()) | ||
encryptor = cipher.encryptor() | ||
aes_cipher = pad(aes_cipher.encode(), 16) | ||
result = encryptor.update(aes_cipher) + encryptor.finalize() | ||
|
||
# print(base64.b64encode(result).decode()) | ||
return str(base64.b64encode(result).decode()) | ||
except Exception as e: | ||
print(e) | ||
return str(e) | ||
|
||
|
||
def decrypt_data(encrypted_data, iv, session_key): | ||
if session_key == "": | ||
return "Please enter key!" | ||
if iv == "": | ||
return "Please enter iv!" | ||
if encrypted_data == "": | ||
return "Please enter encrypt data!" | ||
|
||
try: | ||
base64.decodestring(bytes(session_key, 'utf-8')) | ||
except binascii.Error: | ||
return "key no correct base64" | ||
try: | ||
base64.decodestring(bytes(iv, 'utf-8')) | ||
except binascii.Error: | ||
return "iv no correct base64" | ||
|
||
try: | ||
aes_iv = base64.b64decode(iv) | ||
aes_cipher = base64.b64decode(encrypted_data) | ||
aes_key = base64.b64decode(session_key) | ||
|
||
cipher = Cipher(algorithms.AES(aes_key), modes.CBC(aes_iv), backend=default_backend()) | ||
decryptor = cipher.decryptor() | ||
result = decryptor.update(aes_cipher) + decryptor.finalize() | ||
# result = result.decode() | ||
# result = json.loads(result) | ||
|
||
return str(result[:-int(result[-1])].decode()) | ||
except Exception as e: | ||
print(e) | ||
return str(e) | ||
|
||
|
||
def Batch_GetEn(list): | ||
result = encrypt_data(list[0], list[1], list[2]) | ||
return result | ||
|
||
|
||
def Batch_En(datas, iv, key): | ||
try: | ||
pool = ThreadPoolExecutor(max_workers=10) | ||
tmp_list = [] | ||
tmp_data = "" | ||
for data in datas: | ||
tmp_list.append([data, iv, key]) | ||
results = pool.map(Batch_GetEn, tmp_list) | ||
for i in results: | ||
tmp_data += i | ||
tmp_data += "\n" | ||
tmp_data = tmp_data.strip("\n") | ||
return tmp_data | ||
except Exception as e: | ||
print(e) | ||
return str(e) | ||
|
||
# mode = input("请选择功能:\n加密输入1\n解密输入2\n其他无效\n请输入:") | ||
# if mode == "1": | ||
# session_key = input("请输入SessionKey: ") | ||
# iv = input("请输入本次解密IV: ") | ||
# decrypted_data = input("请输入待加密内容: ") | ||
# | ||
# result = encrypt_data(decrypted_data, iv, session_key) | ||
# | ||
# print("最终的加密结果为: ", result) | ||
# | ||
# elif mode == "2": | ||
# session_key = input("请输入SessionKey: ") | ||
# iv = input("请输入本次加密IV: ") | ||
# encrypted_data = input("请输入待解密内容: ") | ||
# | ||
# result = decrypt_data(encrypted_data, iv, session_key) | ||
# print("最终的解密结果为: ", result) | ||
# | ||
# else: | ||
# print("error!!!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
from UI import * | ||
from functools import partial | ||
import sys | ||
from PyQt5 import QtWidgets | ||
from PyQt5.QtCore import QThread, pyqtSignal | ||
from WX_login_crypt import * | ||
import urllib.parse | ||
|
||
|
||
class MainWindow(QtWidgets.QMainWindow): | ||
def closeEvent(self, event): | ||
try: | ||
reply = QtWidgets.QMessageBox.question(self,'提醒',"是否要退出程序?",QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,QtWidgets.QMessageBox.No) | ||
if reply == QtWidgets.QMessageBox.Yes: | ||
event.accept() | ||
print("主窗口已关闭") | ||
else: | ||
event.ignore() | ||
except Exception as e: | ||
print(e) | ||
|
||
def show_message(ui,msg): | ||
QtWidgets.QMessageBox.information(ui.pushButton, "提示", msg) | ||
|
||
def write_textEdit(ui, data): | ||
ui.textEdit.clear() | ||
ui.textEdit.setText(data) | ||
|
||
def write_textEdit_2(ui, data): | ||
ui.textEdit_2.clear() | ||
ui.textEdit_2.setText(data) | ||
|
||
def En_url(ui): | ||
ui.textEdit_2.setText(urllib.parse.quote(ui.textEdit_2.toPlainText().strip())) | ||
|
||
def Dn_url(ui): | ||
ui.textEdit_2.setText(urllib.parse.unquote(ui.textEdit_2.toPlainText().strip())) | ||
|
||
|
||
def key_function(ui): | ||
|
||
|
||
class En_MyThread(QThread): | ||
my_signal = pyqtSignal(object, str) | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def run(self): | ||
key = ui.lineEdit.text() | ||
iv = ui.lineEdit_2.text() | ||
decrypted_data = ui.textEdit.toPlainText().strip() | ||
result = encrypt_data(decrypted_data, iv, key) | ||
if result is not None: | ||
try: | ||
self.my_signal.emit(ui, result) | ||
except Exception as e: | ||
print(e) | ||
|
||
class De_MyThread(QThread): | ||
my_signal = pyqtSignal(object, str) | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def run(self): | ||
key = ui.lineEdit.text() | ||
iv = ui.lineEdit_2.text() | ||
decrypted_data = ui.textEdit_2.toPlainText().strip() | ||
result = decrypt_data(decrypted_data, iv, key) | ||
if result is not None: | ||
try: | ||
self.my_signal.emit(ui, result) | ||
except Exception as e: | ||
print(e) | ||
|
||
class BatchEn_MyThread(QThread): | ||
my_signal = pyqtSignal(object, str) | ||
def __init__(self): | ||
super().__init__() | ||
|
||
def run(self): | ||
key = ui.lineEdit.text() | ||
iv = ui.lineEdit_2.text() | ||
original = ui.textEdit.toPlainText().strip() | ||
decrypted_data = ui.textEdit_2.toPlainText().strip() | ||
datas = decrypted_data.split("\n") | ||
new_datas = [] | ||
for data in datas: | ||
new_datas.append(original.replace("%%",data)) | ||
result = Batch_En(new_datas,iv,key) | ||
if result is not None: | ||
try: | ||
self.my_signal.emit(ui, result) | ||
except Exception as e: | ||
print(e) | ||
|
||
En_MyThread = En_MyThread() | ||
De_MyThread = De_MyThread() | ||
BatchEn_MyThread = BatchEn_MyThread() | ||
En_MyThread.my_signal.connect(write_textEdit_2) | ||
De_MyThread.my_signal.connect(write_textEdit) | ||
BatchEn_MyThread.my_signal.connect(write_textEdit_2) | ||
ui.pushButton.clicked.connect(partial(En_MyThread.start)) | ||
ui.pushButton_2.clicked.connect(partial(De_MyThread.start)) | ||
ui.pushButton_3.clicked.connect(partial(BatchEn_MyThread.start)) | ||
ui.pushButton_4.clicked.connect(partial(En_url, ui)) | ||
ui.pushButton_5.clicked.connect(partial(Dn_url, ui)) | ||
|
||
|
||
if __name__ == "__main__": | ||
# QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)# 解决高分辨率问题(网上搜的,暂未发现,如果发现有问题可以试试这条) | ||
app = QtWidgets.QApplication(sys.argv) | ||
widget = MainWindow() | ||
Ui_C = QtWidgets.QMainWindow() | ||
ui = Ui_MainWindow() | ||
ui.setupUi(widget) | ||
widget.setWindowTitle("微信一键登录解密") | ||
# widget.setWindowIcon(QtGui.QIcon(":/logo.png")) | ||
widget.show() | ||
key_function(ui) | ||
sys.exit(app.exec_()) |