注释都加了,看不懂拖出去突突了

annn
vernuser 8 months ago
parent 533611cf14
commit b6a3c192d3

@ -4,7 +4,11 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b490c3d2-83ec-4ee0-b2e3-44d7951d4337" name="更改" comment="加了ui" /> <list default="true" id="b490c3d2-83ec-4ee0-b2e3-44d7951d4337" name="更改" comment="加了ui">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/encryption_utils.py" beforeDir="false" afterPath="$PROJECT_DIR$/encryption_utils.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ui.py" beforeDir="false" afterPath="$PROJECT_DIR$/ui.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
@ -59,30 +63,30 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;Python.client.executor&quot;: &quot;Run&quot;, "Python.client.executor": "Run",
&quot;Python.encryption_utils.executor&quot;: &quot;Run&quot;, "Python.encryption_utils.executor": "Run",
&quot;Python.file_transfer.executor&quot;: &quot;Run&quot;, "Python.file_transfer.executor": "Run",
&quot;Python.generate_key.executor&quot;: &quot;Run&quot;, "Python.generate_key.executor": "Run",
&quot;Python.generate_keys.executor&quot;: &quot;Run&quot;, "Python.generate_keys.executor": "Run",
&quot;Python.receiver.executor&quot;: &quot;Run&quot;, "Python.receiver.executor": "Run",
&quot;Python.sender.executor&quot;: &quot;Run&quot;, "Python.sender.executor": "Run",
&quot;Python.server.executor&quot;: &quot;Run&quot;, "Python.server.executor": "Run",
&quot;Python.ui.executor&quot;: &quot;Run&quot;, "Python.ui.executor": "Run",
&quot;Python.utils.executor&quot;: &quot;Run&quot;, "Python.utils.executor": "Run",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;, "RunOnceActivity.git.unshallow": "true",
&quot;git-widget-placeholder&quot;: &quot;annn&quot;, "git-widget-placeholder": "annn",
&quot;last_opened_file_path&quot;: &quot;C:/Users/Asus/Desktop/烽台校园实习/交接资料/实验室仿真台攻击脚本/实验室仿真台攻击脚本/仿真台攻击脚本11.22&quot;, "last_opened_file_path": "D:/college/大三/应用密码学课设",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="RunManager" selected="Python.ui"> <component name="RunManager" selected="Python.ui">
<configuration name="generate_key" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true"> <configuration name="generate_key" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="应用密码学课设" /> <module name="应用密码学课设" />
@ -235,6 +239,8 @@
<workItem from="1734607228597" duration="4000" /> <workItem from="1734607228597" duration="4000" />
<workItem from="1734770663055" duration="28000" /> <workItem from="1734770663055" duration="28000" />
<workItem from="1734779266249" duration="2556000" /> <workItem from="1734779266249" duration="2556000" />
<workItem from="1734782609505" duration="86000" />
<workItem from="1735107821817" duration="149000" />
</task> </task>
<task id="LOCAL-00001" summary="加了互传"> <task id="LOCAL-00001" summary="加了互传">
<option name="closed" value="true" /> <option name="closed" value="true" />
@ -292,7 +298,23 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1734782367798</updated> <updated>1734782367798</updated>
</task> </task>
<option name="localTasksCounter" value="8" /> <task id="LOCAL-00008" summary="加了ui">
<option name="closed" value="true" />
<created>1734782673140</created>
<option name="number" value="00008" />
<option name="presentableId" value="LOCAL-00008" />
<option name="project" value="LOCAL" />
<updated>1734782673140</updated>
</task>
<task id="LOCAL-00009" summary="加了ui">
<option name="closed" value="true" />
<created>1734782691683</created>
<option name="number" value="00009" />
<option name="presentableId" value="LOCAL-00009" />
<option name="project" value="LOCAL" />
<updated>1734782691683</updated>
</task>
<option name="localTasksCounter" value="10" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">

@ -6,28 +6,35 @@ from Crypto.Hash import SHA256
class AsymmetricEncryption: class AsymmetricEncryption:
def __init__(self): def __init__(self):
# 生成2048位的RSA密钥对
self.key_pair = RSA.generate(2048) self.key_pair = RSA.generate(2048)
def get_public_key(self): def get_public_key(self):
# 返回公钥
return self.key_pair.publickey() return self.key_pair.publickey()
def get_private_key(self): def get_private_key(self):
# 返回私钥
return self.key_pair return self.key_pair
def encrypt_with_public_key(self, data, public_key): def encrypt_with_public_key(self, data, public_key):
# 使用公钥加密数据
cipher_rsa = PKCS1_OAEP.new(public_key) cipher_rsa = PKCS1_OAEP.new(public_key)
return cipher_rsa.encrypt(data) return cipher_rsa.encrypt(data)
def decrypt_with_private_key(self, encrypted_data): def decrypt_with_private_key(self, encrypted_data):
# 使用私钥解密数据
cipher_rsa = PKCS1_OAEP.new(self.key_pair) cipher_rsa = PKCS1_OAEP.new(self.key_pair)
return cipher_rsa.decrypt(encrypted_data) return cipher_rsa.decrypt(encrypted_data)
def sign_data(self, data): def sign_data(self, data):
# 对数据进行SHA256哈希然后使用私钥生成签名
h = SHA256.new(data) h = SHA256.new(data)
signature = pkcs1_15.new(self.key_pair).sign(h) signature = pkcs1_15.new(self.key_pair).sign(h)
return signature return signature
def verify_signature(self, data, signature, public_key): def verify_signature(self, data, signature, public_key):
# 对数据进行SHA256哈希然后使用公钥验证签名
h = SHA256.new(data) h = SHA256.new(data)
try: try:
pkcs1_15.new(public_key).verify(h, signature) pkcs1_15.new(public_key).verify(h, signature)
@ -37,11 +44,13 @@ class AsymmetricEncryption:
class SymmetricEncryption: class SymmetricEncryption:
def encrypt(self, data, key): def encrypt(self, data, key):
# 使用AES-GCM模式加密数据
cipher_aes = AES.new(key, AES.MODE_GCM) cipher_aes = AES.new(key, AES.MODE_GCM)
nonce = cipher_aes.nonce nonce = cipher_aes.nonce
ciphertext, tag = cipher_aes.encrypt_and_digest(data) ciphertext, tag = cipher_aes.encrypt_and_digest(data)
return nonce, ciphertext, tag return nonce, ciphertext, tag
def decrypt(self, nonce, ciphertext, tag, key): def decrypt(self, nonce, ciphertext, tag, key):
# 使用AES-GCM模式解密数据并验证
cipher_aes = AES.new(key, AES.MODE_GCM, nonce=nonce) cipher_aes = AES.new(key, AES.MODE_GCM, nonce=nonce)
return cipher_aes.decrypt_and_verify(ciphertext, tag) return cipher_aes.decrypt_and_verify(ciphertext, tag)

@ -10,7 +10,7 @@ class FileTransferApp:
def __init__(self, root): def __init__(self, root):
self.root = root self.root = root
self.root.title("文件传输系统") self.root.title("文件传输系统")
self.root.geometry("800x900") # 增大窗口尺寸 self.root.geometry("800x900") # 窗口大小
self.root.resizable(False, False) # 禁止调整窗口大小 self.root.resizable(False, False) # 禁止调整窗口大小
# 设置窗口背景色 # 设置窗口背景色
@ -21,7 +21,6 @@ class FileTransferApp:
self.receiver_public_key = load_key('receiver_public.pem') self.receiver_public_key = load_key('receiver_public.pem')
self.receiver_private_key = load_key('receiver_private.pem') self.receiver_private_key = load_key('receiver_private.pem')
self.sender_public_key = load_key('sender_public.pem') self.sender_public_key = load_key('sender_public.pem')
# 创建UI # 创建UI
self.create_main_frame() self.create_main_frame()

Loading…
Cancel
Save