123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- :github_url: hide
- .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
- .. DO NOT EDIT THIS FILE, but the AESContext.xml source instead.
- .. The source is found in doc/classes or modules/<name>/doc_classes.
- .. _class_AESContext:
- AESContext
- ==========
- **Inherits:** :ref:`Reference<class_Reference>` **<** :ref:`Object<class_Object>`
- Interface to low level AES encryption features.
- Description
- -----------
- This class provides access to AES encryption/decryption of raw data. Both AES-ECB and AES-CBC mode are supported.
- ::
- extends Node
-
- var aes = AESContext.new()
-
- func _ready():
- var key = "My secret key!!!" # Key must be either 16 or 32 bytes.
- var data = "My secret text!!" # Data size must be multiple of 16 bytes, apply padding if needed.
- # Encrypt ECB
- aes.start(AESContext.MODE_ECB_ENCRYPT, key.to_utf8())
- var encrypted = aes.update(data.to_utf8())
- aes.finish()
- # Decrypt ECB
- aes.start(AESContext.MODE_ECB_DECRYPT, key.to_utf8())
- var decrypted = aes.update(encrypted)
- aes.finish()
- # Check ECB
- assert(decrypted == data.to_utf8())
-
- var iv = "My secret iv!!!!" # IV must be of exactly 16 bytes.
- # Encrypt CBC
- aes.start(AESContext.MODE_CBC_ENCRYPT, key.to_utf8(), iv.to_utf8())
- encrypted = aes.update(data.to_utf8())
- aes.finish()
- # Decrypt CBC
- aes.start(AESContext.MODE_CBC_DECRYPT, key.to_utf8(), iv.to_utf8())
- decrypted = aes.update(encrypted)
- aes.finish()
- # Check CBC
- assert(decrypted == data.to_utf8())
- Methods
- -------
- +-------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | void | :ref:`finish<class_AESContext_method_finish>` **(** **)** |
- +-------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`get_iv_state<class_AESContext_method_get_iv_state>` **(** **)** |
- +-------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :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( ) **)** |
- +-------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`update<class_AESContext_method_update>` **(** :ref:`PoolByteArray<class_PoolByteArray>` src **)** |
- +-------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
- Enumerations
- ------------
- .. _enum_AESContext_Mode:
- .. _class_AESContext_constant_MODE_ECB_ENCRYPT:
- .. _class_AESContext_constant_MODE_ECB_DECRYPT:
- .. _class_AESContext_constant_MODE_CBC_ENCRYPT:
- .. _class_AESContext_constant_MODE_CBC_DECRYPT:
- .. _class_AESContext_constant_MODE_MAX:
- enum **Mode**:
- - **MODE_ECB_ENCRYPT** = **0** --- AES electronic codebook encryption mode.
- - **MODE_ECB_DECRYPT** = **1** --- AES electronic codebook decryption mode.
- - **MODE_CBC_ENCRYPT** = **2** --- AES cipher blocker chaining encryption mode.
- - **MODE_CBC_DECRYPT** = **3** --- AES cipher blocker chaining decryption mode.
- - **MODE_MAX** = **4** --- Maximum value for the mode enum.
- Method Descriptions
- -------------------
- .. _class_AESContext_method_finish:
- - void **finish** **(** **)**
- Close this AES context so it can be started again. See :ref:`start<class_AESContext_method_start>`.
- ----
- .. _class_AESContext_method_get_iv_state:
- - :ref:`PoolByteArray<class_PoolByteArray>` **get_iv_state** **(** **)**
- 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.
- **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>`.
- ----
- .. _class_AESContext_method_start:
- - :ref:`Error<enum_@GlobalScope_Error>` **start** **(** :ref:`Mode<enum_AESContext_Mode>` mode, :ref:`PoolByteArray<class_PoolByteArray>` key, :ref:`PoolByteArray<class_PoolByteArray>` iv=PoolByteArray( ) **)**
- 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>`.
- ----
- .. _class_AESContext_method_update:
- - :ref:`PoolByteArray<class_PoolByteArray>` **update** **(** :ref:`PoolByteArray<class_PoolByteArray>` src **)**
- 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.
- **Note:** The size of ``src`` must be a multiple of 16. Apply some padding if needed.
- .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
- .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
- .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
|