compiling_with_script_encryption_key.rst 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. .. _doc_compiling_with_script_encryption_key:
  2. Compiling with script encryption key
  3. ====================================
  4. .. highlight:: shell
  5. The export dialog gives you the option to encrypt your scripts with a 256-bit
  6. AES key when releasing your project. This will make sure your scripts are not
  7. stored in plain text and can not easily be ripped by some script kiddie.
  8. Of course, the key needs to be stored in the binary, but if it's compiled,
  9. optimized and without symbols, it would take some effort to find it.
  10. For this to work, you need to build the export templates from source,
  11. with that same key.
  12. .. warning::
  13. This will **not** work if you use official, precompiled export templates.
  14. It is absolutely **required** to compile your own export templates to use
  15. PCK encryption.
  16. Step by step
  17. ------------
  18. 1. Generate a 256-bit AES key in hexadecimal format. You can use the aes-256-cbc variant from
  19. `this service <https://asecuritysite.com/encryption/keygen>`_.
  20. Alternatively, you can generate it yourself using
  21. `OpenSSL <https://www.openssl.org/>`__ command-line tools:
  22. ::
  23. openssl rand -hex 32 > godot.gdkey
  24. The output in ``godot.gdkey`` should be similar to:
  25. ::
  26. # NOTE: Do not use the key below! Generate your own key instead.
  27. aeb1bc56aaf580cc31784e9c41551e9ed976ecba10d315db591e749f3f64890f
  28. You can generate the key without redirecting the output to a file, but
  29. that way you can minimize the risk of exposing the key.
  30. 2. Set this key as environment variable in the console that you will use to
  31. compile Godot, like this:
  32. .. tabs::
  33. .. code-tab:: bash Linux/macOS
  34. export SCRIPT_AES256_ENCRYPTION_KEY="your_generated_key"
  35. .. code-tab:: bat Windows (cmd)
  36. set SCRIPT_AES256_ENCRYPTION_KEY=your_generated_key
  37. .. code-tab:: bat Windows (PowerShell)
  38. $env:SCRIPT_AES256_ENCRYPTION_KEY="your_generated_key"
  39. 3. Compile Godot export templates and set them as custom export templates
  40. in the export preset options.
  41. 4. Set the encryption key in the **Script** tab of the export preset:
  42. .. image:: img/script_encryption_key.png
  43. 5. Export the project. The game should run with encrypted scripts now.
  44. Troubleshooting
  45. ---------------
  46. If you get an error like below, it means the key wasn't properly included in
  47. your Godot build. Godot is encrypting the scripts during export, but can't read
  48. them at runtime.
  49. ::
  50. ERROR: open_and_parse: Condition "String::md5(md5.digest) != String::md5(md5d)" is true. Returning: ERR_FILE_CORRUPT
  51. At: core/io/file_access_encrypted.cpp:103
  52. ERROR: load_byte_code: Condition ' err ' is true. returned: err
  53. At: modules/gdscript/gdscript.cpp:755
  54. ERROR: load: Condition ' err != OK ' is true. returned: RES()
  55. At: modules/gdscript/gdscript.cpp:2135
  56. ERROR: Failed loading resource: res://Node2D.gde
  57. At: core/io/resource_loader.cpp:279
  58. ERROR: poll: res://Node2D.tscn:3 - Parse Error: [ext_resource] referenced nonexistent resource at: res://Node2D.gd
  59. At: scene/resources/scene_format_text.cpp:439
  60. ERROR: load: Condition ' err != OK ' is true. returned: RES()
  61. At: core/io/resource_loader.cpp:202
  62. ERROR: Failed loading resource: res://Node2D.tscn
  63. At: core/io/resource_loader.cpp:279
  64. ERROR: Failed loading scene: res://Node2D.tscn
  65. At: main/main.cpp:1727
  66. WARNING: cleanup: ObjectDB Instances still exist!
  67. At: core/object.cpp:2081
  68. ERROR: clear: Resources Still in use at Exit!
  69. At: core/resource.cpp:425