Python qt加解密
from PyQt5.QtWidgets import QApplication, QWidget, QGridLayout, QLabel, QLineEdit, QPushButton
from Crypto.Cipher import AES
import base64
import sys
def encrypt(self):
# 获取输入参数
key = self.keyEdit.text()
plainText = self.plainTextEdit.text()
# 执行加密操作
iv = b'0000000000000000'
cipher = AES.new(key.encode('utf-8'), AES.MODE_CBC, iv)
paddingLen = 16 - (len(plainText) % 16)
plainText += chr(paddingLen) * paddingLen
cipherText = base64.b64encode(cipher.encrypt(plainText.encode('utf-8'))).decode('utf-8')
def decrypt(self):
# 获取输入参数
key = self.keyEdit.text()
cipherText = self.cipherTextEdit.text()
# 执行解密操作
iv = b'0000000000000000'
cipher = AES.new(key.encode('utf-8'), AES.MODE_CBC, iv)
plainText = cipher.decrypt(base64.b64decode(cipherText)).decode('utf-8')