compiling_with_script_encryption_key.rst 3.2 KB

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