Godot Version
4.3
Question
I am working on encryption for a project, and am working on the code for reading back the file with the inputted key, and have been getting multiple errors/crashes. When printing the string of the command-
# method, path and decryption_key are declared above
# path is always a static/absolute path
# the key is using the String of 4 numbers inputted prior to this running
# method is a String which can only be 'encrypted' or 'decrypted'
var opened_file : ConfigFile = ConfigFile.new()
if method == "encrypted":
opened_file.load_encrypted_pass(path, str(decryption_key))
print(str(opened_file.load_encrypted_pass(path, str(decryption_key))))
## prints '16', ERR_FILE_CORRUPT
else:
opened_file.load(path)
I was wondering what causes a file to be considered ‘corrupt’? I can see in my file explorer the file does exist and there are checks prior to this to ensure the file exists at runtime and when opening the file I can see there is text in there. So I was wondering what can cause a file to be deemed corrupt? Since my thought would be either an issue with the file path/access or invalid character(s) inside the document, but I have never altered the document so the only characters inside it should be from when they were encrypted-
# user_data and decryption key are declared above
# like the above code, decryption key is a 4 digit long string of numbers
var passwords_file : ConfigFile = ConfigFile.new()
var tags_file : ConfigFile = ConfigFile.new()
var user_file : ConfigFile = ConfigFile.new()
## ...code to get the data and save them into the config files here...
if not DirAccess.dir_exists_absolute(app_path + "/" + save_folder):
DirAccess.make_dir_absolute(app_path + "/" + save_folder)
# ^ ensure directory exists
var password_path : String = app_path + "/" + save_folder + "/Passwords.ini"
var tag_path : String = app_path + "/" + save_folder + "/Tags.ini"
var user_path : String = app_path + "/" + save_folder + "/UserData.ini"
# ^ store save paths
if user_data["encryption"] == true:
passwords_file.save_encrypted_pass(password_path, str(decryption_key))
tags_file.save_encrypted_pass(tag_path, str(decryption_key))
else:
passwords_file.save(password_path)
tags_file.save(tag_path)
user_file.save(user_path)
# ^ user file is saved here as it is never encrypted
This is the only time the files are touched in any matter other than reading the files, or when I have opened them in notepad to see if they are empty. So what could cause these files to be considered corrupt?
Any help greatly appreciated!