From b7180991a82e479687710a9899b4fc7dc1d51fb7 Mon Sep 17 00:00:00 2001 From: 12513 <1251373914@qq.com> Date: Wed, 25 Dec 2024 20:17:20 +0800 Subject: [PATCH 1/5] =?UTF-8?q?1.=E6=B5=8B=E8=AF=95.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.测试.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 1.测试.py diff --git a/1.测试.py b/1.测试.py new file mode 100644 index 0000000..995c82a --- /dev/null +++ b/1.测试.py @@ -0,0 +1,3 @@ +asdasasdas +asd +这是一个测试 -- 2.34.1 From cd9b228ac32988f3668719b0053e7dc418b9a22a Mon Sep 17 00:00:00 2001 From: 12513 <1251373914@qq.com> Date: Wed, 25 Dec 2024 20:20:50 +0800 Subject: [PATCH 2/5] 2.py --- 2.py | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 2.py diff --git a/2.py b/2.py new file mode 100644 index 0000000..d201088 --- /dev/null +++ b/2.py @@ -0,0 +1,2 @@ +1a5s1d56as1d651 +asd51as6d51as -- 2.34.1 From dc7e06cb156485e72dce3e3f3fb0df61c98d744f Mon Sep 17 00:00:00 2001 From: 12513 <1251373914@qq.com> Date: Wed, 25 Dec 2024 22:52:11 +0800 Subject: [PATCH 3/5] esddd --- 113.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 113.py diff --git a/113.py b/113.py new file mode 100644 index 0000000..493d00b --- /dev/null +++ b/113.py @@ -0,0 +1 @@ +asdas5465 \ No newline at end of file -- 2.34.1 From 806f03a5d4822a32246520c7094eae43ee3461ad Mon Sep 17 00:00:00 2001 From: 12513 <1251373914@qq.com> Date: Wed, 25 Dec 2024 23:30:21 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E9=9D=9E=E5=AF=B9=E7=A7=B0=E5=85=AC?= =?UTF-8?q?=E9=92=A5=E5=8A=A0=E5=AF=86=E5=AF=B9=E7=A7=B0=E5=AF=86=E9=92=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cipher.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 cipher.py diff --git a/cipher.py b/cipher.py new file mode 100644 index 0000000..2d1c471 --- /dev/null +++ b/cipher.py @@ -0,0 +1,61 @@ +import binascii +import hashlib +import base64 + +from Crypto.Cipher import DES +from Crypto.Random import get_random_bytes + +import rsa + + +def des_key_encrypt_with_rsa(): + # 读取 DES 密钥 + with open('sandbox_sender/desPassword.txt', 'r') as des_password_gotcha: + des_pwd = des_password_gotcha.readline().strip() # 移除换行符 + + # 读取公钥 + with open('public_key_receiver.txt', 'r') as pub_key_radio: + public_key_pair_string = pub_key_radio.readline().strip() # 移除换行符 + + # 假设公钥是以 `(n, e)` 格式存储 + try: + public_key_pair_string2pair_step_1 = public_key_pair_string.split(', ') + + public_key_pair_string2pair_step_2_a = public_key_pair_string2pair_step_1[0] + if public_key_pair_string2pair_step_2_a.startswith('('): + public_key_pair_string2pair_step_2_a = public_key_pair_string2pair_step_2_a[1:] + + public_key_pair_string2pair_step_2_b = public_key_pair_string2pair_step_1[1] + if public_key_pair_string2pair_step_2_b.endswith(')'): + public_key_pair_string2pair_step_2_b = public_key_pair_string2pair_step_2_b[:-1] + + # 转换成整数 + n = int(public_key_pair_string2pair_step_2_a) + e = int(public_key_pair_string2pair_step_2_b) + + # 打印输出以验证解析是否正确 + #print(f"Parsed RSA public key: n = {n}, e = {e}") + except Exception as ex: + print(f"Error parsing the RSA public key: {ex}") + return + + # 创建 RSA 公钥对象 + try: + rsa_public_key = RSA.construct((n, e)) # 使用解析出的 (n, e) 创建 RSA 公钥 + rsa_cipher = PKCS1_OAEP.new(rsa_public_key) + + # 将 DES 密钥字符串编码为字节 + des_pwd_bytes = des_pwd.encode() + + # 使用 RSA 加密 DES 密钥 + encrypted_des_pwd = rsa_cipher.encrypt(des_pwd_bytes) + + # 将加密后的 DES 密钥转换为十六进制字符串 + encrypted_des_pwd_hex = encrypted_des_pwd.hex() + + # 将加密后的 DES 密钥保存到文件 + with open('outbox/encrypted_pwd_des.txt', 'w') as encrypted_des_pwd_container: + encrypted_des_pwd_container.write(encrypted_des_pwd_hex) + print("DES password has been encrypted.") + except ValueError as ve: + print(f"Error while constructing RSA public key: {ve}") -- 2.34.1 From 3aaa37ea8ec8ee04093175c18c5bc5604b8715a5 Mon Sep 17 00:00:00 2001 From: 12513 <1251373914@qq.com> Date: Wed, 25 Dec 2024 23:32:01 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E9=9D=9E=E5=AF=B9=E7=A7=B0=E5=85=AC?= =?UTF-8?q?=E9=92=A5=E5=8A=A0=E5=AF=86=E5=AF=B9=E7=A7=B0=E5=AF=86=E9=92=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.测试.py | 3 --- 113.py | 1 - 2.py | 2 -- 3 files changed, 6 deletions(-) delete mode 100644 1.测试.py delete mode 100644 113.py delete mode 100644 2.py diff --git a/1.测试.py b/1.测试.py deleted file mode 100644 index 995c82a..0000000 --- a/1.测试.py +++ /dev/null @@ -1,3 +0,0 @@ -asdasasdas -asd -这是一个测试 diff --git a/113.py b/113.py deleted file mode 100644 index 493d00b..0000000 --- a/113.py +++ /dev/null @@ -1 +0,0 @@ -asdas5465 \ No newline at end of file diff --git a/2.py b/2.py deleted file mode 100644 index d201088..0000000 --- a/2.py +++ /dev/null @@ -1,2 +0,0 @@ -1a5s1d56as1d651 -asd51as6d51as -- 2.34.1