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.

20 lines
683 B

from cryptography.fernet import Fernet
def load_key(key_file_path):
# 从文件中加载对称密钥
with open(key_file_path, 'rb') as key_file:
key = key_file.read()
return key
def decrypt_file(encrypted_file_path, key):
with open(encrypted_file_path, 'rb') as encrypted_file:
ciphertext = encrypted_file.read()
cipher_suite = Fernet(key)
plaintext = cipher_suite.decrypt(ciphertext)
decrypted_file_path = encrypted_file_path.replace('.encrypted', '_decrypted.txt')
with open(decrypted_file_path, 'wb') as decrypted_file:
decrypted_file.write(plaintext)
print('解密成功:' + decrypted_file_path)