There are several steps you can take to prevent a key file from being deleted in Python:
import os
os.chmod('keyfile.txt', 0o400) # set read-only permissions for the owner
import shutil
shutil.move('keyfile.txt', '/etc/secure_folder/')
from cryptography.fernet import Fernet
key = Fernet.generate_key()
f = Fernet(key)
with open('keyfile.txt', 'rb') as file:
file_data = file.read()
encrypted_data = f.encrypt(file_data)
with open('keyfile.txt.encrypted', 'wb') as file:
file.write(encrypted_data)
import subprocess
subprocess.call(['git', 'init'])
subprocess.call(['git', 'add', 'keyfile.txt'])
subprocess.call(['git', 'commit', '-m', 'Initial commit'])
These are some of the steps you can take to prevent a key file from being deleted in Python.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-01-29 11:00:00 +0000
Seen: 7 times
Last updated: Jul 14 '22
How can popen() be used to direct streaming data to TAR?
In Python, can a string be utilized to retrieve a dataframe that has the same name as the string?
What is the method for merging field value and text into a singular line for display?
What is the method for programmatic access to a time series?