{"id":19449041,"url":"https://github.com/skywarth/litebytecapsule","last_synced_at":"2025-04-25T02:32:11.902Z","repository":{"id":41070561,"uuid":"196410949","full_name":"skywarth/LiteByteCapsule","owner":"skywarth","description":"A solution to capsulate byte data in a shell to provide security and validity while sending byte arrays. (for sockets etc.)","archived":true,"fork":false,"pushed_at":"2022-12-08T05:53:48.000Z","size":397,"stargazers_count":3,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"Lib-including-test","last_synced_at":"2025-04-24T20:54:18.614Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/skywarth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-11T14:30:59.000Z","updated_at":"2025-03-13T03:11:14.000Z","dependencies_parsed_at":"2023-01-24T15:15:56.829Z","dependency_job_id":null,"html_url":"https://github.com/skywarth/LiteByteCapsule","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywarth%2FLiteByteCapsule","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywarth%2FLiteByteCapsule/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywarth%2FLiteByteCapsule/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywarth%2FLiteByteCapsule/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skywarth","download_url":"https://codeload.github.com/skywarth/LiteByteCapsule/tar.gz/refs/heads/Lib-including-test","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250742003,"owners_count":21479713,"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":[],"created_at":"2024-11-10T16:29:47.284Z","updated_at":"2025-04-25T02:32:11.611Z","avatar_url":"https://github.com/skywarth.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LiteByteCapsule\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/skywarth/LiteByteCapsule/blob/LibraryVersion/temp-logo-small.png\"\u003e\n\u003c/p\u003e\n\n\n\n![Nuget](https://img.shields.io/nuget/v/LiteByteCapsule.svg) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/04a5655bde6a43b0a37c73d12db5fad5)](https://www.codacy.com/app/skywarth/LiteByteCapsule?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=skywarth/LiteByteCapsule\u0026amp;utm_campaign=Badge_Grade) [![Maintainability](https://api.codeclimate.com/v1/badges/c413df8917e037ec8847/maintainability)](https://codeclimate.com/github/skywarth/LiteByteCapsule/maintainability) [![Build Status](https://dev.azure.com/skywarth/LiteByteCapsule/_apis/build/status/skywarth.LiteByteCapsule?branchName=Lib-including-test)](https://dev.azure.com/skywarth/LiteByteCapsule/_build/latest?definitionId=10\u0026branchName=Lib-including-test) [![Codecov](https://img.shields.io/codecov/c/github/skywarth/LiteByteCapsule.svg)](https://codecov.io/gh/skywarth/LiteByteCapsule) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/2992/badge)](https://bestpractices.coreinfrastructure.org/projects/2992)\n\n\n*NuGet Package: https://www.nuget.org/packages/LiteByteCapsule/*\n\nLiteByteCapsule is a solution/library to encapsulate your byte array packages before sending them over certain protocols (TCP-IP, Socket, API, etc.)\n\n\n## Table Of Contents\n1. Introduction\n    1. [But Why ?](#but-why)\n    2. [How ?](#how)\n2. Installation\n3. Usage\n    1. [About capsulation constants](#constants)\n    2. [Constructors](#constructors)\n    3. [Encapsulating a package](#encapsulation)\n    4. [Exporting encapsulation constants](#exporting)\n    5. [De-encapsulate(validate) a package](#decapsulation)\n    6. [Instance utilities/helpers](#instance-util)\n    7. [Static utilities/helpers](#static-util)\n4. [Tests](#tests)\n5. [Licence](#licence)\n6. [Old documentation](#old)\n    \n\n\n\n## Introduction\n### \u003ca name=\"but-why\"\u003e\u003c/a\u003e But Why ?\n\n\n\nWhen you send your byte arrays on WebSockets (e.g) a connection between sender and receiver is created. This connection is quiet vulnerable to [MitM] [mitm] attacks if you don't use SSL/HTTPS to encrypt the communication. \n \n Even if you use SSL/HTTPS encryption, you are still vulnerable to denial-of-service [(DDoS)] [ddos] attacks on listening port. For e.g: what if somebody floods your listening port on WebSocket with byte arrays with length of 100.000, non-stop. Even if your listening port is async, soon it'll be flooded with noise data. \n \n### \u003ca name=\"how\"\u003e\u003c/a\u003eHow ?\n\n#### For sender(client) side\nLiteByteCapsule encapsulates your package by adding constants(byte values) at the start and end of your original byte array. In other words, your actual package is contained in between series of byte values. That way, if malicious intended person tries to sniff your by packages they won't have an idea where does the actual package start and end. \n  \n#### For receiver(server) side\nInstead of reading all the incoming data/transmission to listening port, use LiteByteCapsule's CheckSyntax() method to drop packages rather fast. It has several measures to prevent reading all the data and stops reading package as soon as one of the measures in syntax doesn't fit. With that, even if somebody sends packages with millions of size, it will be discarded in milliseconds without going through all the package.\n\n## Installation\nSimply initiate this command from your package manager console:\n\n`Install-Package LiteByteCapsule -Version 1.1.6`\n\nOr grab it through NuGet manager by searching \"LiteByteCapsule\".\n\n# Usage\n![alt text][diagram]\n\n\n\n\n\n\n### \u003ca name=\"constants\"\u003e\u003c/a\u003e About encapsulation constants\nBoth encapsulation and decapsulation actions require encapsulation constants to be present. Encapsulation constants are a variable type that is defined in the package **(CapsuleConstants)**. \n\n\n\n\n#### CapsuleConstants Class\n___\nCapsuleConstants class consists:\n\n| Name       |Type           |Cool  |\n| -------------:|:-------------:|:-----|\n| val     | byte|Value property of an CapsuleConstant instance. Byte value for constant.|\n| position     | int      |Position of the constant related to the start position parameter(head). E.g: if position is:0 and head=true, this constant will be the first element in the capsule.|\n| head | bool     |Property to indicate counting for position from start(head) or counting from the end(tail) of the capsule. E.g:Head:false, position:0 will be the last element of the capsule.|\n\nIncase you get lazy and don't want to define bunch of CapsuleConstants by hand, you may refer to :\n\n`CapsuleConstants.GenerateCapsulationConstants(int amount)` is a static method to generate specified amount of CapsuleConstants instances. Returns `Stack\u003cCapsuleConstant\u003e` which could be used to create LiteByteCapsule instance.\n___\n### \u003ca name=\"constructors\"\u003e\u003c/a\u003e Constructors\n\n For encapsulation or decapsulation, you have to create LiteByteCapsule class instance using diverse constructors.\n \n #### **`LiteByteCapsule()`**\n This constructor is used in order to encapsule/decapsulate byte array packages using SmartCapsule technique.\n \n **Smart encapsulation**\n \n | First element      | In between           | Last 4 elements  |\n | :------------- |:-------------:| -----:|\n | 0      | byte[] *| CRC32C **|\n \n_*byte[] is your actual byte array._\n\n_**CRC32C is CRC32C calculation of your actual byte array._  \n\n \n  #### **`LiteByteCapsule(Stack\u003cCapsuleConstant\u003e constants)`**\n  This constructor is used in order to encapsule/decapsulate byte array packages by placing CapsuleConstants into defined positions.\n  \n  **Encapsulation by CapsuleConstant Stack**\n  \n  | Head(start)| In between|Tail(end)|\n  |:------------- |:-------------:| -----:|\n  | Head constants *| byte[] **| Tail constants ***|\n  \n _*Head constants: CapsuleConstants in the stack provided as parameter, which has **head=true** value_\n \n _**byte[] is your actual byte array._\n \n _***Head constants: CapsuleConstants in the stack provided as parameter, which has **head=false** value_\n \n \n   #### **`LiteByteCapsule(byte[] constantFirstPart, byte[] constantLastPart)`**\n   This constructor is used in order to encapsule/decapsulate byte array packages by putting constantFirstPart array to the start of the capsule and constantLastPart array to end of the capsule.\n   \n   **Encapsulation by two byte arrays**\n   \n   | Head(start)| In between|Tail(end)|\n   |:-------------|:-------------:| -----:|\n   | constantFirstPart[]| byte[] *| Tail constantFirstPart |\n\n  \n  _*byte[] is your actual byte array._\n  \n \n \n### \u003ca name=\"encapsulation\"\u003e\u003c/a\u003e Encapsulation\n\nSimply use `ConvertToSyntax(byte[] infactData)` method on your LiteByteCapsule instance.\n```\nLiteByteCapsule lite=new LiteByteCapsule();\n\n//or LiteByteCapsule lite = new LiteByteCapsule(CapsuleConstant.GenerateCapsulationConstants(5));\n\n/*\nor \nStack\u003cCapsulationConstant\u003e constants=new Stack\u003cCapsulationConstant\u003e();\nLiteByteCapsule lite = new LiteByteCapsule(constants);\n*/\n\n/*\nor\nbyte[] head=....\nbyte[] tail=...\nLiteByteCapsule lite=new LiteByteCapsule(head, tail);\n*/\n\n//Then just pass your byte array to ConvertToSyntax method:\nbyte[] myPackage=[12,255,234,116];\nbyte[] capsule=lite.ConvertToSyntax(myPackage);\n//capsule is the encapsulated byte array.\n\n```\n\n### \u003ca name=\"exporting\"\u003e\u003c/a\u003e Exporting Encapsulation Constants\nAfter encapsulation process, you might want to send your export your encapsulation constants to the receiver of the package/capsule so that the receiver can create LiteByteCapsule instance and do decapsulate your package according to your encapsulation constants.\n\n```\n//Use your previously created LiteByteCapsule instance:\n\nstring json=lite.CapsulationConstantsJSONString();\n\n//Then send it to your listener/receiver through an api/websocket/endpoint etc. \n//Receiver will have to parse the json and use it to create LiteByteCapsule instance.\n```\n\n### \u003ca name=\"decapsulation\"\u003e\u003c/a\u003e Decapsulation\n```\n//Create your LiteByteCapsule according to the Capsule Constants provided by the package sender.\n\nStack\u003cCapsuleConstant\u003e constants = JsonConvert.DeserializeObject\u003cStack\u003cCapsuleConstant\u003e\u003e(a);\n\nLiteByteCapsule lite=new LiteByteCapsule(constants);\n\nbyte[] incomingPackage=....\n\nbyte[] actualPackage=lite.CheckSyntax(incomingPackage);\n\n//returns null if the package provided(incomingPackage) is an imposter/doesn't fit to the sequence expected.\n\n\n\n```\n### \u003ca name=\"instance-util\"\u003e\u003c/a\u003e Instance utilities/helpers\n```\n//Stack\u003cCapsuleConstant\u003e constants=...\n\nLiteByteCapsule lite=new LiteByteCapsule(constants);\n\n//From your instance you have access to these utilities:\n\n//CapsulationConstantsJSONString: For converting the encapsulation constants to JSON string\n\nstring json=lite.CapsulationConstantsJSONString();\n\n//GetCapsulationConstants: To get your stack of encapsulation constants that you provided earlier to create an instance of LiteByteCapsule\n\nStack\u003cCapsuleConstant\u003cCapsuleConstant\u003e constants=lite.GetCapsulationConstants();\n\n\n```\n\n### \u003ca name=\"static-util\"\u003e\u003c/a\u003e Static utilities/helpers\n```\n//Generate a random byte array \nbyte[] package=LiteByteCapsule.GetRandomPackage(20);\n\n//Convert a byte array to string\nstring readableFormat=LiteByteCapsule.ConvertToString(package);\n\n//Generate CRC32C Hash/Checksum of a byte array\nstring hash=LiteByteCapsule.GenerateCRC32C(package);\n\n//Add CRC32C calculation to end of an array (4 elements)\nbyte[] capsule=LiteByteCapsule.AddCRC32CToEnd(package);\n\n\n//Check CRC32C integrity of a package (warning, this will expect that the given array has last 4 elements as CRC32C\nbyte[] actualPackage=LiteByteCapsule.CheckCRC32CIntegrity(package);\n\n\n\n```\n## Tests\nPlease do check Azure Devops linked in the badges section or revise CodeCov code coverage reports to see unit test results.\n\n## Licence\n[(MIT Licence)] [licence]\n\n\n\n## Old Documentation\n\n### First create a stack of capsulation constants using CapsuleConstant class\n```\nStack\u003cCapsuleConstant\u003e constants = new Stack\u003cCapsuleConstant\u003e();\n```\n\n### Then push your capsulation constants as you desire\n\n```\nconstants.Push(new CapsuleConstant(5, 1, true));\nconstants.Push(new CapsuleConstant(111, 0, false));\nconstants.Push(new CapsuleConstant(222, 2, true));\nconstants.Push(new CapsuleConstant(172, 0, true));\nconstants.Push(new CapsuleConstant(121, 1, false));\nconstants.Push(new CapsuleConstant(31, 2, false));\nconstants.Push(new CapsuleConstant(54, 3, false));\n```\n### CapsuleConstant instances has these properties by order\n\n```\nnew CapsuleConstant(byteValue,position,startFromTheHead);\n```\n\n### Or create constant stack by random constants using:\n```\nStack\u003cCapsuleConstant\u003e constants=CapsuleConstant.GenerateCapsulationConstants(amount);\n```\nThis will create you a stack of constants which has random values. Since the positioning is dynamic, you won't have to worry about positions of constants in the capsule.\n\n\n### Create LiteByteCapsule instance, constants variable is a stack of CapsuleConstant instances\n```\nLiteByteCapsule lite=new LiteByteCapsule(constants);\n```\n\n### Convert to syntax (capsulation)\n```\nbyte[] capsule=lite.ConvertToSyntax(innerPackage);\n```\nConverts the given byte array to capsule using capsule constant stack passed to constructor of LiteByteCapsule.\n\n### Check syntax (decapsulation)\n```\nbyte[] innerPackage=lite.CheckSyntax(capsule);\n```\nCheckSyntax returns null incase the capsule syntax doesn't match designated capsule constant sequence. Basically null return means imposter package.\n\n### Convert byte array to string\n```\nstring arrayContent=lite.ConvertToString(capsule);\n```\n \n \n [diagram]: ./diagram.jpg \"Flowchart diagram of pathways.\"\n \n \n [//]: #REFERENCES\n \n \n [licence]: https://github.com/skywarth/LiteByteCapsule/blob/Lib-including-test/LICENSE \"MIT Licence\"\n \n \n [mitm]: https://en.wikipedia.org/wiki/Man-in-the-middle_attack \"Man in the Middle Attack in information security - Wikipedia\"\n \n [ddos]: https://en.wikipedia.org/wiki/Denial-of-service_attack \"Denial of service attack\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskywarth%2Flitebytecapsule","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskywarth%2Flitebytecapsule","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskywarth%2Flitebytecapsule/lists"}