parent
055fe16538
commit
9b7716df46
@ -0,0 +1,19 @@
|
||||
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)
|
Loading…
Reference in new issue