1 Star 2 Fork 1

oubayun/File-encryption-and-decryption-tools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
file_en_decryption.py 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
muzilee 提交于 2020-04-16 11:05 +08:00 . all files
from PyQt5.QtWidgets import QApplication, QMainWindow
from file_en_decryption_ui import *
from Crypto.PublicKey import RSA
from PyQt5 import QtGui
import en_decrypt
import platform
import sys
class MyWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MyWindow, self).__init__(parent)
self.setupUi(self)
# 生成密钥
self.generate.clicked.connect(self.createkey)
self.apply.clicked.connect(self.en_decryptionfile)
def createkey(self):
code = "muzilee_www.oubayun.com"
# 生成 2048 位的 RSA 密钥
key = RSA.generate(2048)
encrypted_key = key.exportKey(passphrase=code,
pkcs=8,
protection="scryptAndAES128-CBC")
# 生成私钥
self.private_key.setText(str(encrypted_key, encoding="utf-8"))
with open("rsa_private.key", "wb") as f:
f.write(encrypted_key)
# 生成公钥
self.public_key.setText(
str(key.publickey().exportKey(), encoding="utf-8"))
with open("rsa_public.key", "wb") as f:
f.write(key.publickey().exportKey())
def en_decryptionfile(self):
systemtype = platform.system()
if systemtype == "Windows":
filepathvalue = self.filepath.toPlainText().replace("file:///", "")
else:
filepathvalue = self.filepath.toPlainText().replace("file://", "")
if filepathvalue:
# 解密按钮值(True&False)
decryptionvalue = self.decryption.isChecked()
if str(decryptionvalue) == "True":
destatus = en_decrypt.Descrypt(filepathvalue)
self.public_key.setText(destatus)
else:
enstatus = en_decrypt.Encrypt(filepathvalue)
self.private_key.setText(enstatus)
if __name__ == '__main__':
app = QApplication(sys.argv)
myWin = MyWindow()
myWin.setWindowIcon(QtGui.QIcon("logo.ico"))
myWin.show()
sys.exit(app.exec_())
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/oubayun/File-encryption-and-decryption-tools.git
git@gitee.com:oubayun/File-encryption-and-decryption-tools.git
oubayun
File-encryption-and-decryption-tools
File-encryption-and-decryption-tools
master

搜索帮助