47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
import argparse
|
|
import os
|
|
import base64
|
|
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
|
|
from cryptography.hazmat.primitives import padding
|
|
|
|
|
|
def decrypt_file(encrypted_file_path, output_file_path=None):
|
|
key_Mes = "fb8MH7yIuVUeCp5W4S9cKFtsHaxXIP/zvkO36wNNcO4="
|
|
key = base64.b64decode(key_Mes.encode("ascii"))
|
|
|
|
with open(encrypted_file_path, 'rb') as f:
|
|
encrypted_data = f.read()
|
|
|
|
cipher = Cipher(
|
|
algorithms.AES(key),
|
|
modes.ECB()
|
|
)
|
|
|
|
decryptor = cipher.decryptor()
|
|
padded_data = decryptor.update(encrypted_data) + decryptor.finalize()
|
|
|
|
# Remove PKCS7 padding
|
|
unpadder = padding.PKCS7(128).unpadder()
|
|
data = unpadder.update(padded_data) + unpadder.finalize()
|
|
|
|
if output_file_path is None:
|
|
output_file_path = encrypted_file_path.replace('.enc', '.dec')
|
|
|
|
with open(output_file_path, 'wb') as output_file:
|
|
output_file.write(data)
|
|
|
|
print(f"Decrypted to: {output_file_path}")
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description='Decrypt file')
|
|
parser.add_argument('-p', '--path', help='Path to encrypted file', required=True)
|
|
parser.add_argument('-o', '--out_file', help='Output file path', default=None)
|
|
args = parser.parse_args()
|
|
return args
|
|
|
|
|
|
if __name__ == '__main__':
|
|
args = main()
|
|
decrypt_file(args.path, args.out_file)
|