USecurity is a security component used in the Unity project. It provides encryption of commonly used data types at runtime, PlayerPrefs storage encryption, and a quick call interface for encryption and decryption of common encryption algorithms.
-
- 2.1. Anti Cheat Value - Runtime Data Encryption
- 2.1.1. Introduction
- 2.1.2. C# Type
- 2.1.3. Unity Type
- 2.1.4. Working Principle
- 2.1.5. How To Use
- 2.1.6. Attention
- 2.2. PlayerPrefsAES
- 2.2.1. Introduction
- 2.2.2. How To Use
- 2.1. Anti Cheat Value - Runtime Data Encryption
-
- 3.1. Introduction
- 3.2. How To Use
- Copy the folder to the
UnityProject/Assets/Plugins/
directory. - Set the key file in the
Resources/
subdirectory of each type of encryption needed under theEncDec/
directory, and set the encryption key you want, or clickCreate Key
in the component menu to generate a random key. - If the project does not use the
Resources.Load
method to load resources, you can adjust the storage path of the key configuration file by yourself and replace the interface implementation ofUSecurityInterface.Load
, or you can do secondary encryption on the key resource file.
AntiCheatValue is the core function of the USecurity component. It provides runtime encrypted data types corresponding to the native data types of C# and Unity. In most cases, these data types can directly replace the original native data in the project. Type, and use the same style and method as the original type, which can be efficiently accessed so that existing projects can quickly obtain runtime anti-cheating capabilities.
Anti Cheat Type | Source Tyoe |
---|---|
cBool | bool |
cByte | byte |
cChar | char |
cDecimal | decimal |
cFloat | float |
cInt | int |
cLong | long |
cShort | short |
cString | string |
Provides most commonly used C# data types, and all implement the interfaces of IComparable
, IFormattable
, IConvertible
, IEquatable
, IFormattable
, IEnumerable
, ICloneable
, etc. contained in the native type, and implement ISerializable
`Interface to support serialized storage. All types implement implicit conversion and common operator overloading with corresponding primitive types.
Anti Cheat Type | Source Tyoe |
---|---|
cColor | Color |
cQuaternion | Quaternion |
cVector2 | Vector2 |
cVector3 | Vector3 |
cVector4 | Vector4 |
The Unity encrypted data type is a secondary encapsulation based on the C# encryption type. For example, cVector3 essentially encapsulates 3 cFloat, so it can be combined with actual needs to expand other complex encrypted data types.
By encapsulating the native type, the upper-level business logic accesses and manipulates the encapsulated type without directly operating the actual internal value. When the encapsulation type is operated, the real value passed in will be processed through encryption algorithms, memory offset, etc., and the processing methods for different data types are different. It can effectively avoid conventional cheating methods for searching and locating memory data.
// Directly replace the native type
public cInt num = 1;
// Mutual assignment operations with native types
public int a = 1;
public cInt b = a;
a = b;
// Perform regular mathematical operations directly with native types
public int left = 1;
public cInt right = 1;
right++;
public int add = left + right;
// Routine mathematical operations between different encryption types
public cInt num1 = 1;
public cFloat num2 = 1f;
float result = num1 * num2;
// Compare with native type value
public cInt i1 = 1;
public int i2 = 1;
public cInt i3 = 1;
public Debug.Log(i1 == i2);
public Debug.Log(i1 == i3);
// Support using the Convert interface for type conversion
public cInt srcValue = 1;
public int dstValue = Convert.ToInt32(srcValue);
- Since the dynamic encryption key is regenerated every time it runs, the same actual value will be different every time it runs, so the internal value should not be used for storage.
- Encryption operations have a certain performance overhead. Use simple numeric encryption types as much as possible and apply only to important data as much as possible.
Provides AES encryption and decryption package for PlayerPrefs archive function, the style is consistent with the native interface, and some additional access interfaces for commonly used data types are added, and PlayerPrefs can be used as the main storage Directly replace in the project of the method to quickly obtain storage encryption capabilities.
// Save value
PlayerPrefsAES.SetInt("Key", 100);
// Load value
var value = PlayerPrefsAES.GetInt("Key");
// Delete value
PlayerPrefsAES.DeleteKey("Key");
// Delete all data
PlayerPrefsAES.DeleteAll();
// Save & Write data
PlayerPrefsAES.Save();
DFA is the full name Deterministic Finite Automaton, which is a more commonly used sensitive word filtering algorithm. This component compares and filters the user text input in the project with the sensitive word dictionary.
// Set to replace sensitive characters
DFAUtil.ReplaceSymbol = "*";
// Set the thesaurus file separator
DFAUtil.Separator = new[] { ",", "\n", "\r" };
// Initialize with pre-prepared thesaurus text
var text = Resources.Load<TextAsset>("DFA").text;
DFAUtil.Init(text);
// Filter input content
var content = ".....";
var result = DFAUtil.FilterWords(content, out var isLimit);
Debug.Log(isLimit);
Debug.Log(result);
Provides AES encryption and decryption of strings and files, with faster speed and higher security.
Provides DES encryption and decryption of strings and files, which is slower and less secure.
Provide RC4 encryption and decryption of strings, the fastest speed, security is not guaranteed, and the password can be variable length.
It provides RSA signature and verification, encryption and decryption of strings and files, which is slower and has the highest security. The password is generated by the program.
Provide base64 encoding and decoding of text.
Provides standard MD5 value and short MD5 value calculation for text and files.