2
0

compiling_with_script_encryption_key.rst 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 an 256bit
  6. AES key, when releasing your game. 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. Step by step
  13. ------------
  14. 1. Generate a 256bit AES key in HEX. You can use the aes-256-cbc variant from
  15. `this service <https://asecuritysite.com/encryption/keygen>`_.
  16. Alternatively, you can generate it yourself by using OpenSSL:
  17. ::
  18. openssl rand -hex 32 > godot.gdkey
  19. The output in ``godot.gdkey`` should be similar to:
  20. ::
  21. aeb1bc56aaf580cc31784e9c41551e9ed976ecba10d315db591e749f3f64890f
  22. You can generate the key without redirecting the output to a file, but
  23. that way you can minimize the risk of exposing the key.
  24. 2. Set this key as environment variable in the console that you will use to
  25. compile Godot, like this:
  26. .. tabs::
  27. .. code-tab:: bash Linux/macOS
  28. export SCRIPT_AES256_ENCRYPTION_KEY="your_generated_key"
  29. .. code-tab:: bat Windows (cmd)
  30. set SCRIPT_AES256_ENCRYPTION_KEY=your_generated_key
  31. .. code-tab:: bat Windows (PowerShell)
  32. $env:SCRIPT_AES256_ENCRYPTION_KEY="your_generated_key"
  33. 3. Compile Godot export templates and set them as custom export templates
  34. in the export preset options.
  35. 4. Set the encryption key in the ``Script`` tab of the export preset:
  36. .. image:: img/script_encryption_key.png
  37. 5. Export the project. The game should run with encrypted scripts now.
  38. Possible Errors
  39. ---------------
  40. If you get an error like below, it means the key wasn't properly included in
  41. your Godot build. Godot is encrypting the scripts during export, but can't read
  42. them at runtime.
  43. ::
  44. ERROR: open_and_parse: Condition "String::md5(md5.digest) != String::md5(md5d)" is true. Returning: ERR_FILE_CORRUPT
  45. At: core/io/file_access_encrypted.cpp:103
  46. ERROR: load_byte_code: Condition ' err ' is true. returned: err
  47. At: modules/gdscript/gdscript.cpp:755
  48. ERROR: load: Condition ' err != OK ' is true. returned: RES()
  49. At: modules/gdscript/gdscript.cpp:2135
  50. ERROR: Failed loading resource: res://Node2D.gde
  51. At: core/io/resource_loader.cpp:279
  52. ERROR: poll: res://Node2D.tscn:3 - Parse Error: [ext_resource] referenced nonexistent resource at: res://Node2D.gd
  53. At: scene/resources/scene_format_text.cpp:439
  54. ERROR: load: Condition ' err != OK ' is true. returned: RES()
  55. At: core/io/resource_loader.cpp:202
  56. ERROR: Failed loading resource: res://Node2D.tscn
  57. At: core/io/resource_loader.cpp:279
  58. ERROR: Failed loading scene: res://Node2D.tscn
  59. At: main/main.cpp:1727
  60. WARNING: cleanup: ObjectDB Instances still exist!
  61. At: core/object.cpp:2081
  62. ERROR: clear: Resources Still in use at Exit!
  63. At: core/resource.cpp:425