要查看一个 Blowfish 加密的文件,您可以使用以下方法:
openssl enc -d -blowfish -in encrypted_file.txt -out decrypted_file.txt -k password
其中,encrypted_file.txt
是要解密的文件,decrypted_file.txt
是解密后的文件,password
是加密时使用的密码。
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
def decrypt_file(key, iv, input_file, output_file):
cipher = Cipher(algorithms.Blowfish(key), modes.CBC(iv), backend=default_backend())
decryptor = cipher.decryptor()
with open(input_file, 'rb') as file_in, open(output_file, 'wb') as file_out:
while True:
chunk = file_in.read(8192)
if not chunk:
break
decrypted_chunk = decryptor.update(chunk)
file_out.write(decrypted_chunk)
decrypted_chunk = decryptor.finalize()
file_out.write(decrypted_chunk)
key = b'secret_key'
iv = b'initialization_vector'
input_file = 'encrypted_file.txt'
output_file = 'decrypted_file.txt'
decrypt_file(key, iv, input_file, output_file)
其中,key
是加密时使用的密钥,iv
是加密时使用的初始化向量,encrypted_file.txt
是要解密的文件,decrypted_file.txt
是解密后的文件。请确保安装了 Cryptography 库。
请注意,为了解密 Blowfish 加密的文件,您需要正确的密码或密钥。如果没有正确的密码或密钥,您将无法成功解密文件。请确保您有合法的权限和许可来解密文件。