You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.8 KiB
47 lines
1.8 KiB
def des_pwd_decrypt():
|
|
with open('sent/encrypted_pwd_des.txt', 'r') as des_pwd_container:
|
|
des_pwd_encrypted = des_pwd_container.readline()
|
|
with open('sandbox_receiver/private_key_receiver.txt', 'r') as prv_key_radio:
|
|
private_key_pair_string = prv_key_radio.readline()
|
|
private_key_pair_string2pair_step_1 = private_key_pair_string.split(', ')
|
|
|
|
# 手动实现removeprefix
|
|
def remove_prefix(s, prefix):
|
|
if s.startswith(prefix):
|
|
return s[len(prefix):]
|
|
return s
|
|
|
|
# 手动实现removesuffix
|
|
def remove_suffix(s, suffix):
|
|
if s.endswith(suffix):
|
|
return s[:-len(suffix)]
|
|
return s
|
|
|
|
# 修改原代码
|
|
private_key_pair_string2pair_step_2_a = remove_prefix(private_key_pair_string2pair_step_1[0], '(')
|
|
private_key_pair_string2pair_step_2_b = remove_suffix(private_key_pair_string2pair_step_1[1], ')')
|
|
private_key_pair_string2pair_step_2_c = remove_suffix(private_key_pair_string2pair_step_1[2], ')')
|
|
|
|
private_key_pair = int(private_key_pair_string2pair_step_2_a), int(private_key_pair_string2pair_step_2_b),int(private_key_pair_string2pair_step_2_c)
|
|
#print(private_key_pair)
|
|
rsa_private_key = RSA.construct(private_key_pair)# 使用解析出的 (n, e) 创建 RSA 公钥
|
|
rsa_cipher = PKCS1_OAEP.new(rsa_private_key)
|
|
|
|
# rsa_private_key = public_key.save_pkcs1()
|
|
|
|
# 将 DES 密钥字符串编码为字节
|
|
des_pwd_encrypted_bytes = bytes.fromhex(des_pwd_encrypted)
|
|
|
|
# 使用 RSA 加密 DES 密钥
|
|
decrypted_des_pwd = rsa_cipher.decrypt(des_pwd_encrypted_bytes)
|
|
|
|
with open('inbox/desPassword.txt', 'wb') as des_password_file:
|
|
des_password_file.write(decrypted_des_pwd)
|
|
|
|
#print(decrypted_des_pwd)
|
|
# 将加密后的 DES 密钥转换为十六进制字符串
|
|
encrypted_des_pwd_hex = decrypted_des_pwd.hex()
|
|
|
|
|
|
return decrypted_des_pwd
|