Here's the format for encrypted files from all versions of Godot from 2014 to 3.5.2. Endianness is configured using File.endian_swap.
Each file type has its own format. Below describes encrypted files only:
Here is some BASH code that can successfully open encrypted files (where the "savegame.bin" is a file encrypted by Godot, and "PA55W0RD" is the passphase):
< savegame.bin tail -c+33 | openssl aes-256-ecb -d -nosalt -nopad -K $(printf PA55W0RD | md5sum | head -c32 | xxd -c32 -p)
This can be made into a POSIX function:
godot_decrypt_with_pass () {
tail -c+33 | openssl aes-256-ecb -d -nosalt -nopad -K $(printf "$1" | md5sum | head -c32 | xxd -c32 -p)
}
Which can then be used as such (for example):
< savegame.bin godot_decrypt_with_pass PA55W0RD
Doing so will print the decrypted contents to stdout. Note that these implementations return extraneous null characters at the end of stream. See my follow up post for an updated version that handles this correctly.
Note(s) to future programmers: This is not an example of secure encryption. Do not use this as an example for critical security components. Godot is an excellent F(L)OSS game engine and only provides these features for casual obfuscation. Iff security is desired:
- Do not use ECB ever, for anything (other than education purposes).
- Always use an IV.
- Always use a valid padding scheme (such as PKCS#7 or ISO/IEC 9797-1.2) to avoid corrupting the tail end of your data.
- Furthermore, never throw away entropy from the passphrase and instead consider using a standard password based key derivation function (such as PBKDF2 or HKDF).
Other exercises include writing back encrypted files, and reading and writing files compressed with Godot. Let me know if there are any issues, or if implementations in other programming languages are desired. Do not contact me via direct message - this is a burner account that I no longer have access to.
Thank you.