compiling_with_script_encryption_key.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. .. _doc_compiling_with_script_encryption_key:
  2. Compiling with PCK encryption key
  3. =================================
  4. .. highlight:: shell
  5. The export dialog gives you the option to encrypt your PCK file with a 256-bit
  6. AES key when releasing your project. This will make sure your scenes, scripts
  7. and other resources are not stored in plain text and can not easily be ripped
  8. by some script kiddie.
  9. Of course, the key needs to be stored in the binary, but if it's compiled,
  10. optimized and without symbols, it would take some effort to find it.
  11. For this to work, you need to build the export templates from source,
  12. with that same key.
  13. .. warning::
  14. This will **not** work if you use official, precompiled export templates.
  15. It is absolutely **required** to compile your own export templates to use
  16. PCK encryption.
  17. .. warning::
  18. By default, Android exports store assets directly in the APK file and
  19. aren't affected by PCK encryption. To use PCK encryption on Android, enable
  20. **APK expansion** in the export options.
  21. Step by step
  22. ------------
  23. 1. Generate a 256-bit AES key in hexadecimal format. You can use the aes-256-cbc variant from
  24. `this service <https://asecuritysite.com/encryption/keygen>`_.
  25. Alternatively, you can generate it yourself using
  26. `OpenSSL <https://www.openssl.org/>`__ command-line tools:
  27. ::
  28. openssl rand -hex 32 > godot.gdkey
  29. The output in ``godot.gdkey`` should be similar to:
  30. ::
  31. # NOTE: Do not use the key below! Generate your own key instead.
  32. aeb1bc56aaf580cc31784e9c41551e9ed976ecba10d315db591e749f3f64890f
  33. You can generate the key without redirecting the output to a file, but
  34. that way you can minimize the risk of exposing the key.
  35. 2. Set this key as environment variable in the console that you will use to
  36. compile Godot, like this:
  37. .. tabs::
  38. .. code-tab:: bash Linux/macOS
  39. export SCRIPT_AES256_ENCRYPTION_KEY="your_generated_key"
  40. .. code-tab:: bat Windows (cmd)
  41. set SCRIPT_AES256_ENCRYPTION_KEY=your_generated_key
  42. .. code-tab:: bat Windows (PowerShell)
  43. $env:SCRIPT_AES256_ENCRYPTION_KEY="your_generated_key"
  44. 3. Compile Godot export templates and set them as custom export templates
  45. in the export preset options.
  46. 4. Set the encryption key in the **Encryption** tab of the export preset:
  47. .. image:: img/encryption_key.png
  48. 5. Add filters for the files/folders to encrypt. **By default**, include filters
  49. are empty and **nothing will be encrypted**.
  50. 6. Export the project. The project should run with the files encrypted now.
  51. Troubleshooting
  52. ---------------
  53. If you get an error like below, it means the key wasn't properly included in
  54. your Godot build. Godot is encrypting PCK file during export, but can't read
  55. it at runtime.
  56. ::
  57. ERROR: open_and_parse: Condition "String::md5(md5.digest) != String::md5(md5d)" is true. Returning: ERR_FILE_CORRUPT
  58. At: core/io/file_access_encrypted.cpp:103