diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json deleted file mode 100644 index c7b5bc9..0000000 --- a/.config/dotnet-tools.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": 1, - "isRoot": true, - "tools": { - "dotnet-stryker": { - "version": "3.10.0", - "commands": [ - "dotnet-stryker" - ] - } - } -} \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 40730c5..1eb76aa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,7 +1,7 @@ name: Deploy NuGet Package env: - PROJECT_PATH: './Pandatech.Crypto/Pandatech.Crypto.csproj' + PROJECT_PATH: './src/Pandatech.Crypto/Pandatech.Crypto.csproj' OUTPUT_DIR: 'nupkgs' NUGET_SOURCE: 'https://api.nuget.org/v3/index.json' NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} @@ -18,21 +18,18 @@ jobs: dotnet-version: [ '8.x.x' ] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Setup .NET Core - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v3 with: dotnet-version: ${{ matrix.dotnet-version }} - name: Build run: dotnet build ${{ env.PROJECT_PATH }} - - name: Test - run: dotnet test ${{ env.PROJECT_PATH }} --collect:"XPlat Code Coverage" - - name: Pack - run: dotnet pack ${{ env.PROJECT_PATH }} --output ${{ env.OUTPUT_DIR }} + run: dotnet pack ${{ env.PROJECT_PATH }} --output ${{ env.OUTPUT_DIR }} - name: Publish - run: dotnet nuget push ${{ env.OUTPUT_DIR }}/*.nupkg -k ${{ env.NUGET_API_KEY }} -s ${{ env.NUGET_SOURCE }} + run: dotnet nuget push ${{ env.OUTPUT_DIR }}/*.nupkg -k ${{ env.NUGET_API_KEY }} -s ${{ env.NUGET_SOURCE }} \ No newline at end of file diff --git a/Pandatech.Crypto/Readme.md b/Pandatech.Crypto/Readme.md deleted file mode 100644 index 37c7664..0000000 --- a/Pandatech.Crypto/Readme.md +++ /dev/null @@ -1,141 +0,0 @@ -# PandaTech.Crypto - -## Introduction - -Pandatech.Crypto is a powerful cryptographic utility library backed by 99% test coverage through unit tests. The library -offers an array of static methods for secure data operations, including AES256 encryption and decryption, Argon2Id -password hashing and verification, as well as utilities for generating cryptographic random bytes and passwords. - -Designed to work efficiently in containerized environments, the library performs effectively even with limited -resources—hash generation takes under 500ms on a container with 1 vCore and 1GB of RAM. - -## Features - -* **AES 256-bit Encryption/Decryption:** Encrypt your data and get the IV and encrypted bytes in one array. Decrypt it - back to its original form, seamlessly handling the IV. Note that you have option to encrypt with hash and decrypt - ignoring hash. (for cases where you want to apply filtering on the encrypted data or check uniqueness of the encrypted - data) -* **Argon2Id Hashing:** Perform password hashing and verification with a focus on security and performance, leveraging - the Argon2Id algorithm. -* **SHA-3 Hashing:** Utilize 512-bit SHA-3 hashing for various applications. -* **Random Number/Password Generation:** Generate cryptographic random bytes, AES256 keys, or strong passwords with - specific character sets. -* **Performance Optimized:** Tested to run efficiently in resource-constrained environments. -* **High Test Coverage:** Confidence backed by 99% unit test coverage. - -## Installation - -To use `PandaTech.Crypto` in your project, install the NuGet package using the following command in the Package Manager -Console: -`Install-Package PandaTech.Crypto` or, search for "PandaTech.Crypto" in the NuGet Package Manager and install it from -there. - -## How to Use - -### 1. Configuring Dependency Injection - -First, you'll need to configure Aes256 and Argon2Id in your application. To do so, add the following code to -your `Program.cs` file: - -```csharp -using Pandatech.Crypto; - -// For Aes256 -builder.services.AddPandatechCryptoAes256(options => -{ - options.Key = "YourAes256KeyHere"; // Make sure to use a secure key -}); - -// For Argon2Id overriding default configurations - builder.services.AddPandatechCryptoArgon2Id(options => -{ - options.SaltSize = 16; - options.DegreeOfParallelism = 8; - options.Iterations = 5; - options.MemorySize = 128 * 1024; -}); -``` - -### 2. AES256 Class - -#### Immutable Configurations - -1. **IV**: A random IV is generated for each Encryption, enhancing security. -2. **PaddingMode**: PKCS7 - -#### Encryption/Decryption methods with hashing - -```csharp -byte[] cipherText = aes256.Encrypt("your-plaintext"); -string plainText = aes256.Decrypt(cipherText); -``` - -#### Encryption/Decryption methods without hashing - -```csharp -byte[] cipherText = aes256.Encrypt("your-plaintext", false); -string plainText = aes256.Decrypt(cipherText, false); -``` - -#### Encryption/Decryption methods with custom key (overriding options for one time) - -```csharp -string customKey = "your-custom-base64-encoded-key"; -byte[] cipherText = aes256.Encrypt("your-plaintext", customKey); -string plainText = aes256.Decrypt(cipherText, customKey); -``` - -### 2. Argon2id Class - -#### Default Configurations - -1. **Salt**: A random salt is generated for each password hash, enhancing security. -2. **DegreeOfParallelism**: 8 -3. **Iterations**: 5 -4. **MemorySize**: 128 MB - -Hash password and verify hash - -```csharp -// Example usage for hashing -var hashedPassword = _argon2Id.HashPassword("yourPassword"); - -// Example usage for verifying a hash -var isPasswordValid = _argon2Id.VerifyHash("yourPassword", hashedPassword); -``` - -### 3. Random Class - -```csharp -var randomBytes = Random.GenerateBytes(16); -var aesKey = Random.GenerateAes256KeyString(); -``` - -### 4. Password Class - -```csharp -var includeUppercase = true; -var includeLowercase = true; -var includeDigits = true; -var includeSpecialChars = true; - -//Method for generating random password -string password = Password.GenerateRandom(16, includeUppercase, includeLowercase, includeDigits, includeSpecialChars); - -//Method for validation of password -bool isValid = Password.Validate(password, 16, includeUppercase, includeLowercase, includeDigits, includeSpecialChars); -``` - -### 5. Sha3 Class - -```csharp -// Example usage for generating hash -var sha3Hash = Sha3.Hash("yourPlainText"); - -// Example usage for verifying a hash -var isHashValid = Sha3.VerifyHash("yourPlainText", sha3Hash); -``` - -## License - -PandaTech.Crypto is licensed under the MIT License. \ No newline at end of file diff --git a/global.json b/global.json deleted file mode 100644 index dad2db5..0000000 --- a/global.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "sdk": { - "version": "8.0.0", - "rollForward": "latestMajor", - "allowPrerelease": true - } -} \ No newline at end of file diff --git a/Pandatech.Crypto/pandatech.png b/pandatech.png similarity index 100% rename from Pandatech.Crypto/pandatech.png rename to pandatech.png diff --git a/Pandatech.Crypto.sln b/src/Pandatech.Crypto.sln similarity index 92% rename from Pandatech.Crypto.sln rename to src/Pandatech.Crypto.sln index 637ca74..4e6185a 100644 --- a/Pandatech.Crypto.sln +++ b/src/Pandatech.Crypto.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.7.34024.191 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pandatech.Crypto.Tests", "Pandatech.Crypto.Tests\Pandatech.Crypto.Tests.csproj", "{89D6535F-549C-4091-BF21-96565F098C3F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pandatech.Crypto.Tests", "../tests/Pandatech.Crypto.Tests\Pandatech.Crypto.Tests.csproj", "{89D6535F-549C-4091-BF21-96565F098C3F}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pandatech.Crypto", "Pandatech.Crypto\Pandatech.Crypto.csproj", "{97B88123-20B1-4F0A-82E7-DFDD08A03B7C}" EndProject diff --git a/Pandatech.Crypto.sln.DotSettings b/src/Pandatech.Crypto.sln.DotSettings similarity index 100% rename from Pandatech.Crypto.sln.DotSettings rename to src/Pandatech.Crypto.sln.DotSettings diff --git a/Pandatech.Crypto/Aes256.cs b/src/Pandatech.Crypto/Aes256.cs similarity index 100% rename from Pandatech.Crypto/Aes256.cs rename to src/Pandatech.Crypto/Aes256.cs diff --git a/Pandatech.Crypto/Argon2Id.cs b/src/Pandatech.Crypto/Argon2Id.cs similarity index 100% rename from Pandatech.Crypto/Argon2Id.cs rename to src/Pandatech.Crypto/Argon2Id.cs diff --git a/Pandatech.Crypto/HostBuilderExtensions.cs b/src/Pandatech.Crypto/HostBuilderExtensions.cs similarity index 100% rename from Pandatech.Crypto/HostBuilderExtensions.cs rename to src/Pandatech.Crypto/HostBuilderExtensions.cs diff --git a/Pandatech.Crypto/Options.cs b/src/Pandatech.Crypto/Options.cs similarity index 100% rename from Pandatech.Crypto/Options.cs rename to src/Pandatech.Crypto/Options.cs diff --git a/Pandatech.Crypto/Pandatech.Crypto.csproj b/src/Pandatech.Crypto/Pandatech.Crypto.csproj similarity index 73% rename from Pandatech.Crypto/Pandatech.Crypto.csproj rename to src/Pandatech.Crypto/Pandatech.Crypto.csproj index 116ea01..64b01fd 100644 --- a/Pandatech.Crypto/Pandatech.Crypto.csproj +++ b/src/Pandatech.Crypto/Pandatech.Crypto.csproj @@ -4,25 +4,20 @@ net8.0 enable enable - 2.2.1 - Pandatech.Crypto Pandatech pandatech.png Readme.md + 2.2.2 + Pandatech.Crypto + Pandatech, library, encryption, hash, algorythms, security PandaTech.Crypto is a .NET library simplifying common cryptograhic functions. https://github.com/PandaTechAM/be-lib-pandatech-crypto - Nullable byte in aes256 decrypt + Structure change - - True - - - - True - \ - + + diff --git a/Pandatech.Crypto/Password.cs b/src/Pandatech.Crypto/Password.cs similarity index 100% rename from Pandatech.Crypto/Password.cs rename to src/Pandatech.Crypto/Password.cs diff --git a/Pandatech.Crypto/Random.cs b/src/Pandatech.Crypto/Random.cs similarity index 100% rename from Pandatech.Crypto/Random.cs rename to src/Pandatech.Crypto/Random.cs diff --git a/Pandatech.Crypto/Sha3.cs b/src/Pandatech.Crypto/Sha3.cs similarity index 100% rename from Pandatech.Crypto/Sha3.cs rename to src/Pandatech.Crypto/Sha3.cs diff --git a/Pandatech.Crypto.Tests/Aes256Tests.cs b/tests/Pandatech.Crypto.Tests/Aes256Tests.cs similarity index 100% rename from Pandatech.Crypto.Tests/Aes256Tests.cs rename to tests/Pandatech.Crypto.Tests/Aes256Tests.cs diff --git a/Pandatech.Crypto.Tests/Argon2IdTests.cs b/tests/Pandatech.Crypto.Tests/Argon2IdTests.cs similarity index 100% rename from Pandatech.Crypto.Tests/Argon2IdTests.cs rename to tests/Pandatech.Crypto.Tests/Argon2IdTests.cs diff --git a/Pandatech.Crypto.Tests/GlobalUsings.cs b/tests/Pandatech.Crypto.Tests/GlobalUsings.cs similarity index 100% rename from Pandatech.Crypto.Tests/GlobalUsings.cs rename to tests/Pandatech.Crypto.Tests/GlobalUsings.cs diff --git a/Pandatech.Crypto.Tests/HostBuilderTests.cs b/tests/Pandatech.Crypto.Tests/HostBuilderTests.cs similarity index 100% rename from Pandatech.Crypto.Tests/HostBuilderTests.cs rename to tests/Pandatech.Crypto.Tests/HostBuilderTests.cs diff --git a/Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj b/tests/Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj similarity index 92% rename from Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj rename to tests/Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj index 4231b75..a579b60 100644 --- a/Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj +++ b/tests/Pandatech.Crypto.Tests/Pandatech.Crypto.Tests.csproj @@ -23,7 +23,7 @@ - + diff --git a/Pandatech.Crypto.Tests/PasswordTests.cs b/tests/Pandatech.Crypto.Tests/PasswordTests.cs similarity index 100% rename from Pandatech.Crypto.Tests/PasswordTests.cs rename to tests/Pandatech.Crypto.Tests/PasswordTests.cs diff --git a/Pandatech.Crypto.Tests/RandomTests.cs b/tests/Pandatech.Crypto.Tests/RandomTests.cs similarity index 100% rename from Pandatech.Crypto.Tests/RandomTests.cs rename to tests/Pandatech.Crypto.Tests/RandomTests.cs diff --git a/Pandatech.Crypto.Tests/Sha3Tests.cs b/tests/Pandatech.Crypto.Tests/Sha3Tests.cs similarity index 100% rename from Pandatech.Crypto.Tests/Sha3Tests.cs rename to tests/Pandatech.Crypto.Tests/Sha3Tests.cs