diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 500c1d5..3c797d9 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,11 @@
-
+
+
+
+
+
@@ -59,30 +63,30 @@
- {
- "keyToString": {
- "Python.client.executor": "Run",
- "Python.encryption_utils.executor": "Run",
- "Python.file_transfer.executor": "Run",
- "Python.generate_key.executor": "Run",
- "Python.generate_keys.executor": "Run",
- "Python.receiver.executor": "Run",
- "Python.sender.executor": "Run",
- "Python.server.executor": "Run",
- "Python.ui.executor": "Run",
- "Python.utils.executor": "Run",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "RunOnceActivity.git.unshallow": "true",
- "git-widget-placeholder": "annn",
- "last_opened_file_path": "C:/Users/Asus/Desktop/烽台校园实习/交接资料/实验室仿真台攻击脚本/实验室仿真台攻击脚本/仿真台攻击脚本11.22",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
@@ -235,6 +239,8 @@
+
+
@@ -292,7 +298,23 @@
1734782367798
-
+
+
+ 1734782673140
+
+
+
+ 1734782673140
+
+
+
+ 1734782691683
+
+
+
+ 1734782691683
+
+
diff --git a/encryption_utils.py b/encryption_utils.py
index 4a916a7..39eb992 100644
--- a/encryption_utils.py
+++ b/encryption_utils.py
@@ -6,28 +6,35 @@ from Crypto.Hash import SHA256
class AsymmetricEncryption:
def __init__(self):
+ # 生成2048位的RSA密钥对
self.key_pair = RSA.generate(2048)
def get_public_key(self):
+ # 返回公钥
return self.key_pair.publickey()
def get_private_key(self):
+ # 返回私钥
return self.key_pair
def encrypt_with_public_key(self, data, public_key):
+ # 使用公钥加密数据
cipher_rsa = PKCS1_OAEP.new(public_key)
return cipher_rsa.encrypt(data)
def decrypt_with_private_key(self, encrypted_data):
+ # 使用私钥解密数据
cipher_rsa = PKCS1_OAEP.new(self.key_pair)
return cipher_rsa.decrypt(encrypted_data)
def sign_data(self, data):
+ # 对数据进行SHA256哈希,然后使用私钥生成签名
h = SHA256.new(data)
signature = pkcs1_15.new(self.key_pair).sign(h)
return signature
def verify_signature(self, data, signature, public_key):
+ # 对数据进行SHA256哈希,然后使用公钥验证签名
h = SHA256.new(data)
try:
pkcs1_15.new(public_key).verify(h, signature)
@@ -37,11 +44,13 @@ class AsymmetricEncryption:
class SymmetricEncryption:
def encrypt(self, data, key):
+ # 使用AES-GCM模式加密数据
cipher_aes = AES.new(key, AES.MODE_GCM)
nonce = cipher_aes.nonce
ciphertext, tag = cipher_aes.encrypt_and_digest(data)
return nonce, ciphertext, tag
def decrypt(self, nonce, ciphertext, tag, key):
+ # 使用AES-GCM模式解密数据并验证
cipher_aes = AES.new(key, AES.MODE_GCM, nonce=nonce)
return cipher_aes.decrypt_and_verify(ciphertext, tag)
\ No newline at end of file
diff --git a/ui.py b/ui.py
index ef4e8c6..1c66fa1 100644
--- a/ui.py
+++ b/ui.py
@@ -10,7 +10,7 @@ class FileTransferApp:
def __init__(self, root):
self.root = root
self.root.title("文件传输系统")
- self.root.geometry("800x900") # 增大窗口尺寸
+ self.root.geometry("800x900") # 窗口大小
self.root.resizable(False, False) # 禁止调整窗口大小
# 设置窗口背景色
@@ -21,7 +21,6 @@ class FileTransferApp:
self.receiver_public_key = load_key('receiver_public.pem')
self.receiver_private_key = load_key('receiver_private.pem')
self.sender_public_key = load_key('sender_public.pem')
-
# 创建UI
self.create_main_frame()