class_aescontext.rst 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/AESContext.xml.
  6. .. _class_AESContext:
  7. AESContext
  8. ==========
  9. **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
  10. Interface to low level AES encryption features.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. This class provides access to AES encryption/decryption of raw data. Both AES-ECB and AES-CBC mode are supported.
  15. ::
  16. extends Node
  17. var aes = AESContext.new()
  18. func _ready():
  19. var key = "My secret key!!!" # Key must be either 16 or 32 bytes.
  20. var data = "My secret text!!" # Data size must be multiple of 16 bytes, apply padding if needed.
  21. # Encrypt ECB
  22. aes.start(AESContext.MODE_ECB_ENCRYPT, key.to_utf8())
  23. var encrypted = aes.update(data.to_utf8())
  24. aes.finish()
  25. # Decrypt ECB
  26. aes.start(AESContext.MODE_ECB_DECRYPT, key.to_utf8())
  27. var decrypted = aes.update(encrypted)
  28. aes.finish()
  29. # Check ECB
  30. assert(decrypted == data.to_utf8())
  31. var iv = "My secret iv!!!!" # IV must be of exactly 16 bytes.
  32. # Encrypt CBC
  33. aes.start(AESContext.MODE_CBC_ENCRYPT, key.to_utf8(), iv.to_utf8())
  34. encrypted = aes.update(data.to_utf8())
  35. aes.finish()
  36. # Decrypt CBC
  37. aes.start(AESContext.MODE_CBC_DECRYPT, key.to_utf8(), iv.to_utf8())
  38. decrypted = aes.update(encrypted)
  39. aes.finish()
  40. # Check CBC
  41. assert(decrypted == data.to_utf8())
  42. .. rst-class:: classref-reftable-group
  43. Methods
  44. -------
  45. .. table::
  46. :widths: auto
  47. +-------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | void | :ref:`finish<class_AESContext_method_finish>` **(** **)** |
  49. +-------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`get_iv_state<class_AESContext_method_get_iv_state>` **(** **)** |
  51. +-------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Error<enum_@GlobalScope_Error>` | :ref:`start<class_AESContext_method_start>` **(** :ref:`Mode<enum_AESContext_Mode>` mode, :ref:`PoolByteArray<class_PoolByteArray>` key, :ref:`PoolByteArray<class_PoolByteArray>` iv=PoolByteArray( ) **)** |
  53. +-------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`update<class_AESContext_method_update>` **(** :ref:`PoolByteArray<class_PoolByteArray>` src **)** |
  55. +-------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. .. rst-class:: classref-section-separator
  57. ----
  58. .. rst-class:: classref-descriptions-group
  59. Enumerations
  60. ------------
  61. .. _enum_AESContext_Mode:
  62. .. rst-class:: classref-enumeration
  63. enum **Mode**:
  64. .. _class_AESContext_constant_MODE_ECB_ENCRYPT:
  65. .. rst-class:: classref-enumeration-constant
  66. :ref:`Mode<enum_AESContext_Mode>` **MODE_ECB_ENCRYPT** = ``0``
  67. AES electronic codebook encryption mode.
  68. .. _class_AESContext_constant_MODE_ECB_DECRYPT:
  69. .. rst-class:: classref-enumeration-constant
  70. :ref:`Mode<enum_AESContext_Mode>` **MODE_ECB_DECRYPT** = ``1``
  71. AES electronic codebook decryption mode.
  72. .. _class_AESContext_constant_MODE_CBC_ENCRYPT:
  73. .. rst-class:: classref-enumeration-constant
  74. :ref:`Mode<enum_AESContext_Mode>` **MODE_CBC_ENCRYPT** = ``2``
  75. AES cipher blocker chaining encryption mode.
  76. .. _class_AESContext_constant_MODE_CBC_DECRYPT:
  77. .. rst-class:: classref-enumeration-constant
  78. :ref:`Mode<enum_AESContext_Mode>` **MODE_CBC_DECRYPT** = ``3``
  79. AES cipher blocker chaining decryption mode.
  80. .. _class_AESContext_constant_MODE_MAX:
  81. .. rst-class:: classref-enumeration-constant
  82. :ref:`Mode<enum_AESContext_Mode>` **MODE_MAX** = ``4``
  83. Maximum value for the mode enum.
  84. .. rst-class:: classref-section-separator
  85. ----
  86. .. rst-class:: classref-descriptions-group
  87. Method Descriptions
  88. -------------------
  89. .. _class_AESContext_method_finish:
  90. .. rst-class:: classref-method
  91. void **finish** **(** **)**
  92. Close this AES context so it can be started again. See :ref:`start<class_AESContext_method_start>`.
  93. .. rst-class:: classref-item-separator
  94. ----
  95. .. _class_AESContext_method_get_iv_state:
  96. .. rst-class:: classref-method
  97. :ref:`PoolByteArray<class_PoolByteArray>` **get_iv_state** **(** **)**
  98. Get the current IV state for this context (IV gets updated when calling :ref:`update<class_AESContext_method_update>`). You normally don't need this function.
  99. \ **Note:** This function only makes sense when the context is started with :ref:`MODE_CBC_ENCRYPT<class_AESContext_constant_MODE_CBC_ENCRYPT>` or :ref:`MODE_CBC_DECRYPT<class_AESContext_constant_MODE_CBC_DECRYPT>`.
  100. .. rst-class:: classref-item-separator
  101. ----
  102. .. _class_AESContext_method_start:
  103. .. rst-class:: classref-method
  104. :ref:`Error<enum_@GlobalScope_Error>` **start** **(** :ref:`Mode<enum_AESContext_Mode>` mode, :ref:`PoolByteArray<class_PoolByteArray>` key, :ref:`PoolByteArray<class_PoolByteArray>` iv=PoolByteArray( ) **)**
  105. Start the AES context in the given ``mode``. A ``key`` of either 16 or 32 bytes must always be provided, while an ``iv`` (initialization vector) of exactly 16 bytes, is only needed when ``mode`` is either :ref:`MODE_CBC_ENCRYPT<class_AESContext_constant_MODE_CBC_ENCRYPT>` or :ref:`MODE_CBC_DECRYPT<class_AESContext_constant_MODE_CBC_DECRYPT>`.
  106. .. rst-class:: classref-item-separator
  107. ----
  108. .. _class_AESContext_method_update:
  109. .. rst-class:: classref-method
  110. :ref:`PoolByteArray<class_PoolByteArray>` **update** **(** :ref:`PoolByteArray<class_PoolByteArray>` src **)**
  111. Run the desired operation for this AES context. Will return a :ref:`PoolByteArray<class_PoolByteArray>` containing the result of encrypting (or decrypting) the given ``src``. See :ref:`start<class_AESContext_method_start>` for mode of operation.
  112. \ **Note:** The size of ``src`` must be a multiple of 16. Apply some padding if needed.
  113. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  114. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  115. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  116. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`