{"id":13662124,"url":"https://github.com/ls9512/USecurity","last_synced_at":"2025-04-25T06:31:36.073Z","repository":{"id":48168784,"uuid":"319562931","full_name":"ls9512/USecurity","owner":"ls9512","description":"USecurity is a security and anti-cheat component used in the Unity project.","archived":false,"fork":false,"pushed_at":"2022-03-23T17:52:33.000Z","size":46,"stargazers_count":32,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-24T08:33:17.320Z","etag":null,"topics":["anticheat","encrypt","encryption","encryption-decryption","game","game-development","safety","security","u3d","unity","unity3d","unity3d-plugin"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ls9512.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-08T07:40:48.000Z","updated_at":"2025-01-16T12:57:39.000Z","dependencies_parsed_at":"2022-09-09T06:51:14.708Z","dependency_job_id":null,"html_url":"https://github.com/ls9512/USecurity","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ls9512%2FUSecurity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ls9512%2FUSecurity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ls9512%2FUSecurity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ls9512%2FUSecurity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ls9512","download_url":"https://codeload.github.com/ls9512/USecurity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250767269,"owners_count":21483949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anticheat","encrypt","encryption","encryption-decryption","game","game-development","safety","security","u3d","unity","unity3d","unity3d-plugin"],"created_at":"2024-08-02T05:01:49.765Z","updated_at":"2025-04-25T06:31:31.064Z","avatar_url":"https://github.com/ls9512.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# USecurity\n\n**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.\n\n![topLanguage](https://img.shields.io/github/languages/top/ls9512/USecurity)\n![size](https://img.shields.io/github/languages/code-size/ls9512/USecurity)\n![issue](https://img.shields.io/github/issues/ls9512/USecurity)\n![license](https://img.shields.io/github/license/ls9512/USecurity)\n![last](https://img.shields.io/github/last-commit/ls9512/USecurity)\n[![996.icu](https://img.shields.io/badge/link-996.icu-red.svg)](https://996.icu)\n\n[[中文文档]](README_CN.md)\n\n\u003c!-- vscode-markdown-toc --\u003e\n* 1. [Quick Start](#QuickStart)\n* 2. [Anti Cheat](#AntiCheat)\n\t* 2.1. [Anti Cheat Value - Runtime Data Encryption](#AntiCheatValue-RuntimeDataEncryption)\n\t\t* 2.1.1. [Introduction](#Introduction)\n\t\t* 2.1.2. [C# Type](#CType)\n\t\t* 2.1.3. [Unity Type](#UnityType)\n\t\t* 2.1.4. [Working Principle](#WorkingPrinciple)\n\t\t* 2.1.5. [How To Use](#HowToUse)\n\t\t* 2.1.6. [Attention](#Attention)\n\t* 2.2. [PlayerPrefsAES](#PlayerPrefsAES)\n\t\t* 2.2.1. [Introduction](#Introduction-1)\n\t\t* 2.2.2. [How To Use](#HowToUse-1)\n* 3. [DFA - Sensitive Word Filtering](#DFA-SensitiveWordFiltering)\n\t* 3.1. [Introduction](#Introduction-1)\n\t* 3.2. [How To Use](#HowToUse-1)\n* 4. [Encrypt / Decrypt](#EncryptDecrypt)\n\t* 4.1. [AES](#AES)\n\t* 4.2. [DES](#DES)\n\t* 4.3. [RC4](#RC4)\n\t* 4.4. [RSA](#RSA)\n\t* 4.5. [Base64](#Base64)\n* 5. [MD5](#MD5)\n\n\u003c!-- vscode-markdown-toc-config\n\tnumbering=true\n\tautoSave=true\n\t/vscode-markdown-toc-config --\u003e\n\u003c!-- /vscode-markdown-toc --\u003e\n\n##  1. \u003ca name='QuickStart'\u003e\u003c/a\u003eQuick Start\n1. Copy the folder to the `UnityProject/Assets/Plugins/` directory.\n2. Set the key file in the `Resources/` subdirectory of each type of encryption needed under the `EncDec/` directory, and set the encryption key you want, or click `Create Key` in the component menu to generate a random key.\n3. 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 of `USecurityInterface.Load`, or you can do secondary encryption on the key resource file.\n\n##  2. \u003ca name='AntiCheat'\u003e\u003c/a\u003eAnti Cheat\n\n###  2.1. \u003ca name='AntiCheatValue-RuntimeDataEncryption'\u003e\u003c/a\u003eAnti Cheat Value - Runtime Data Encryption\n\n####  2.1.1. \u003ca name='Introduction'\u003e\u003c/a\u003eIntroduction\n**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.\n\n####  2.1.2. \u003ca name='CType'\u003e\u003c/a\u003eC# Type\n|Anti Cheat Type|Source Tyoe|\n|-|-|\n|cBool|bool|\n|cByte|byte|\n|cChar|char|\n|cDecimal|decimal|\n|cFloat|float|\n|cInt|int|\n|cLong|long|\n|cShort|short|\n|cString|string|\n\nProvides 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.\n\n####  2.1.3. \u003ca name='UnityType'\u003e\u003c/a\u003eUnity Type\n|Anti Cheat Type|Source Tyoe|\n|-|-|\n|cColor|Color|\n|cQuaternion|Quaternion|\n|cVector2|Vector2|\n|cVector3|Vector3|\n|cVector4|Vector4|\n\nThe 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.\n\n####  2.1.4. \u003ca name='WorkingPrinciple'\u003e\u003c/a\u003eWorking Principle\nBy 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.\n\n####  2.1.5. \u003ca name='HowToUse'\u003e\u003c/a\u003eHow To Use\n```cs\n// Directly replace the native type\npublic cInt num = 1;\n\n// Mutual assignment operations with native types\npublic int a = 1;\npublic cInt b = a;\na = b;\n\n// Perform regular mathematical operations directly with native types\npublic int left = 1;\npublic cInt right = 1;\nright++;\npublic int add = left + right;\n\n// Routine mathematical operations between different encryption types\npublic cInt num1 = 1;\npublic cFloat num2 = 1f;\nfloat result = num1 * num2;\n\n// Compare with native type value\npublic cInt i1 = 1;\npublic int i2 = 1;\npublic cInt i3 = 1;\npublic Debug.Log(i1 == i2);\npublic Debug.Log(i1 == i3);\n\n// Support using the Convert interface for type conversion\npublic cInt srcValue = 1;\npublic int dstValue = Convert.ToInt32(srcValue);\n```\n\n####  2.1.6. \u003ca name='Attention'\u003e\u003c/a\u003eAttention\n* 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.\n* 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.\n\n###  2.2. \u003ca name='PlayerPrefsAES'\u003e\u003c/a\u003ePlayerPrefsAES\n\n####  2.2.1. \u003ca name='Introduction-1'\u003e\u003c/a\u003eIntroduction\nProvides **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.\n\n####  2.2.2. \u003ca name='HowToUse-1'\u003e\u003c/a\u003eHow To Use\n```cs\n// Save value\nPlayerPrefsAES.SetInt(\"Key\", 100);\n\n// Load value\nvar value = PlayerPrefsAES.GetInt(\"Key\");\n\n// Delete value\nPlayerPrefsAES.DeleteKey(\"Key\");\n\n// Delete all data\nPlayerPrefsAES.DeleteAll();\n\n// Save \u0026 Write data\nPlayerPrefsAES.Save();\n```\n\n***\n\n##  3. \u003ca name='DFA-SensitiveWordFiltering'\u003e\u003c/a\u003eDFA - Sensitive Word Filtering\n\n###  3.1. \u003ca name='Introduction-1'\u003e\u003c/a\u003eIntroduction\n**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.\n\n###  3.2. \u003ca name='HowToUse-1'\u003e\u003c/a\u003eHow To Use\n```cs\n// Set to replace sensitive characters\nDFAUtil.ReplaceSymbol = \"*\";\n\n// Set the thesaurus file separator\nDFAUtil.Separator = new[] { \",\", \"\\n\", \"\\r\" };\n\n// Initialize with pre-prepared thesaurus text\nvar text = Resources.Load\u003cTextAsset\u003e(\"DFA\").text;\nDFAUtil.Init(text);\n\n// Filter input content\nvar content = \".....\";\nvar result = DFAUtil.FilterWords(content, out var isLimit);\nDebug.Log(isLimit);\nDebug.Log(result);\n```\n\n***\n\n##  4. \u003ca name='EncryptDecrypt'\u003e\u003c/a\u003eEncrypt / Decrypt\n\n###  4.1. \u003ca name='AES'\u003e\u003c/a\u003eAES\nProvides AES encryption and decryption of strings and files, with faster speed and higher security.\n\n###  4.2. \u003ca name='DES'\u003e\u003c/a\u003eDES\nProvides DES encryption and decryption of strings and files, which is slower and less secure.\n\n###  4.3. \u003ca name='RC4'\u003e\u003c/a\u003eRC4\nProvide RC4 encryption and decryption of strings, the fastest speed, security is not guaranteed, and the password can be variable length.\n\n###  4.4. \u003ca name='RSA'\u003e\u003c/a\u003eRSA\nIt 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.\n\n###  4.5. \u003ca name='Base64'\u003e\u003c/a\u003eBase64\nProvide base64 encoding and decoding of text.\n\n***\n\n##  5. \u003ca name='MD5'\u003e\u003c/a\u003eMD5\nProvides standard MD5 value and short MD5 value calculation for text and files.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fls9512%2FUSecurity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fls9512%2FUSecurity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fls9512%2FUSecurity/lists"}