compiling_with_script_encryption_key.rst 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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
  32. set 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. returned: 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