Wrapper to encrypt and store a value to avoid leave plain data in the memory.
More...
Inherits ISerializationCallbackReceiver.
Inherited by CryptoCache< T, U >, and CryptoObject< T, U >.
Wrapper to encrypt and store a value to avoid leave plain data in the memory.
Please note:
- Reference this wrapper in need, instead of keeping the real value.
- Like deserializing, the decrypted value won't be the same instance before encrypting.
Commonly, a derived class may:
- Declare a non-generic type for Unity serialization.
- Override
ToValue()
or ToText()
for custom conversion between plain text.
- Or override
value
property to wrap custom behavior, e.g., obfuscated cache.
- Template Parameters
-
T | The value type. |
U | The editee type, commonly use T or string . |
Initialize with the specified value.
- Parameters
-
override string ToString |
( |
| ) |
|
Return the plain text.
- Returns
- A
string
represents this.
Read the stored real value.
- Returns
- Value.
void WriteValue |
( |
T |
value | ) |
|
|
protected |
Write the real value to store.
- Parameters
-
Read the decrypted plain text.
- Returns
- Plain text.
void WriteText |
( |
string |
text, |
|
|
bool |
force = false |
|
) |
| |
|
protected |
Encrypt the plain text and write with a new key.
- Parameters
-
text | Plain text. |
force | If to force update, otherwise check changed in editor. |
virtual T ToValue |
( |
string |
text | ) |
|
|
protectedvirtual |
Convert the decrypted text to the real value.
- Parameters
-
- Returns
- Value.
Reimplemented in CryptoObject< T, U >.
virtual string ToText |
( |
T |
value | ) |
|
|
protectedvirtual |
Convert the real value to the text to encrypt.
- Parameters
-
- Returns
- Text.
Reimplemented in CryptoObject< T, U >.
virtual void OnBeforeSerialize |
( |
| ) |
|
|
virtual |
OnBeforeSerialize, check if saving to obfuscate the plain data, otherwise prepare the editee value.
Reimplemented in CryptoCache< T, U >.
virtual void OnAfterDeserialize |
( |
| ) |
|
|
virtual |
OnAfterDeserialize, check if to store and clean the editee value.
Reimplemented in CryptoCache< T, U >.
Read the stored value to the editee value.
- Returns
- Editee.
virtual void WriteEditee |
( |
U |
editee | ) |
|
|
protectedvirtual |
Write the editee value to the stored value.
- Parameters
-
virtual string ValidateEditee |
( |
| ) |
|
|
protectedvirtual |
Validate the editee value, return null
if correct, otherwise the warning message.
- Returns
- Message.