Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Compiling with PCK encryption key¶
The export dialog gives you the option to encrypt your PCK file with a 256-bit AES key when releasing your project. This will make sure your scenes, scripts and other resources are not stored in plain text and can not easily be ripped by some script kiddie.
当然,密钥需要存储在二进制文件中,但是经过编译、优化、去除符号后,是需要花费一些精力才能找到的。
为此,您需要使用相同的密钥,从源代码构建导出模板。
警告
如果你使用官方预编译的导出模板,是不会起作用的。要使用 PCK 加密,绝对必须自己编译导出模板。
警告
By default, Android exports store assets directly in the APK file and aren't affected by PCK encryption. To use PCK encryption on Android, enable APK expansion in the export options.
渐进式教程¶
生成十六进制的 256 位 AES 密钥。您可以使用此服务的 aes-256-cbc 版本。
或者,您可以通过使用 OpenSSL 命令行工具自己生成:
openssl rand -hex 32 > godot.gdkey
godot.gdkey
中的输出应该类似:# NOTE: Do not use the key below! Generate your own key instead. aeb1bc56aaf580cc31784e9c41551e9ed976ecba10d315db591e749f3f64890f
不将输出重定向到文件也可以生成密钥,但这样能将暴露密钥的风险降到最低。
在控制台中将此处的密钥(key)设置为环境变量,编译 Godot 时会用到,如下所示:
export SCRIPT_AES256_ENCRYPTION_KEY="your_generated_key"
set SCRIPT_AES256_ENCRYPTION_KEY=your_generated_key
$env:SCRIPT_AES256_ENCRYPTION_KEY="your_generated_key"
编译 Godot 导出模板,并在导出预设的选项中将它们设置为自定义导出模板。
Set the encryption key in the Encryption tab of the export preset:
Add filters for the files/folders to encrypt. By default, include filters are empty and nothing will be encrypted.
Export the project. The project should run with the files encrypted now.
故障排除¶
If you get an error like below, it means the key wasn't properly included in your Godot build. Godot is encrypting PCK file during export, but can't read it at runtime.
ERROR: open_and_parse: Condition "String::md5(md5.digest) != String::md5(md5d)" is true. Returning: ERR_FILE_CORRUPT
At: core/io/file_access_encrypted.cpp:103