WH.Encryption 1.0.0

dotnet add package WH.Encryption --version 1.0.0
                    
NuGet\Install-Package WH.Encryption -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WH.Encryption" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WH.Encryption" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="WH.Encryption" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WH.Encryption --version 1.0.0
                    
#r "nuget: WH.Encryption, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WH.Encryption@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WH.Encryption&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=WH.Encryption&version=1.0.0
                    
Install as a Cake Tool

WH Encrypt API

A comprehensive cross-platform encryption library providing consistent AES-256-GCM encryption across Node.js and C# environments.

๐Ÿ—๏ธ Project Structure

wh-encrypt-api/
โ”œโ”€โ”€ nodejs/                    # Node.js/Browser implementation
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ index.js          # Main encryption library
โ”‚   โ”‚   โ””โ”€โ”€ index.d.ts        # TypeScript definitions
โ”‚   โ”œโ”€โ”€ test-compatibility.js # Cross-platform tests
โ”‚   โ””โ”€โ”€ package.json          # Node.js package config
โ”œโ”€โ”€ csharp/                   # C# implementation
โ”‚   โ””โ”€โ”€ csharp/
โ”‚       โ”œโ”€โ”€ EncryptionService.cs      # Main encryption service
โ”‚       โ”œโ”€โ”€ EncryptionConstants.cs    # Shared constants
โ”‚       โ”œโ”€โ”€ EncryptionException.cs    # Exception handling
โ”‚       โ”œโ”€โ”€ EncryptedResponse.cs      # Response wrapper
โ”‚       โ”œโ”€โ”€ TestProgram.cs            # Cross-platform tests
โ”‚       โ””โ”€โ”€ csharp.csproj            # C# project config
โ”œโ”€โ”€ .github/
โ”‚   โ””โ”€โ”€ workflows/            # CI/CD pipelines
โ”œโ”€โ”€ LICENSE                   # License information
โ”œโ”€โ”€ .gitignore               # Git ignore rules
โ”œโ”€โ”€ CHANGELOG.md             # Version history
โ””โ”€โ”€ README.md                # This file

๐Ÿš€ Features

  • AES-256-GCM Encryption: Industry-standard authenticated encryption with integrity verification
  • Cross-Platform Compatible: Full compatibility between Node.js and C# implementations
  • PBKDF2 Key Derivation: Secure key derivation with 100,000 iterations and SHA-256
  • TypeScript Support: Complete type definitions for Node.js/TypeScript projects
  • Browser Support: Web Crypto API compatibility for frontend applications
  • Multi-Framework: Supports .NET 6.0+ and .NET 8.0+ with conditional compilation
  • Comprehensive Testing: Extensive test suites with cross-platform validation
  • Security Validated: Tampering detection, key separation, and format validation
  • CI/CD Ready: Automated testing, building, and deployment workflows

๐Ÿ“ฆ Packages

Node.js Package

  • Package Name: wh-encrypt-api
  • Location: nodejs/
  • Environments: Node.js servers, Browser clients
  • Entry Points:
    • createEncryption() - Node.js crypto module
    • createBrowserEncryption() - Web Crypto API

C# Package

  • Package Name: WH.Encryption
  • Location: csharp/csharp/
  • Environments: .NET 6.0+, .NET 8.0+
  • Main Class: EncryptionService
  • Compatible: Full interoperability with Node.js implementation

๐Ÿ”ง Installation

Node.js/JavaScript

npm install wh-encrypt-api

C# (.NET)

dotnet add package WH.Encryption

๐Ÿ’ป Usage Examples

Node.js Backend

const { createEncryption } = require("wh-encrypt-api");

// Initialize encryption service
const encryption = createEncryption("your-secret-key");

// Encrypt data (any JSON-serializable object)
const userData = { id: 123, name: "John Doe", active: true };
const encrypted = encryption.encryptData(userData);

// Decrypt data
const decrypted = encryption.decryptData(encrypted);
console.log(decrypted); // { id: 123, name: 'John Doe', active: true }

Browser Frontend

import { createBrowserEncryption } from "wh-encrypt-api";

// Initialize browser-compatible encryption
const encryption = createBrowserEncryption("your-secret-key");

// Encrypt data (async in browser)
const userData = { id: 123, name: "John Doe", active: true };
const encrypted = await encryption.encryptData(userData);

// Decrypt data (async in browser)
const decrypted = await encryption.decryptData(encrypted);
console.log(decrypted); // { id: 123, name: 'John Doe', active: true }

C# (.NET)

using WH.Encryption;

// Initialize encryption service
using var encryption = new EncryptionService("your-secret-key");

// Encrypt data (any object that can be JSON serialized)
var userData = new { id = 123, name = "John Doe", active = true };
string encrypted = encryption.EncryptData(userData);

// Decrypt data with generic type
var decrypted = encryption.DecryptData<dynamic>(encrypted);
Console.WriteLine(decrypted); // { "id": 123, "name": "John Doe", "active": true }

// Or decrypt to specific type
var typedData = encryption.DecryptData<UserData>(encrypted);

Cross-Platform Data Exchange

// Node.js: Encrypt data
const nodeEncryption = createEncryption("shared-secret");
const encrypted = nodeEncryption.encryptData({
  message: "Hello from Node.js!",
});

// Send encrypted to C# service...
// C#: Decrypt the same data
using var csharpEncryption = new EncryptionService("shared-secret");
var decrypted = csharpEncryption.DecryptData<dynamic>(encryptedFromNodejs);
// Successfully decrypts Node.js encrypted data

๐Ÿ”’ Security Specifications

Encryption Algorithm

  • Cipher: AES-256-GCM (Galois/Counter Mode)
  • Key Size: 256 bits (32 bytes)
  • IV Size: 96 bits (12 bytes) - randomly generated per operation
  • Authentication Tag: 128 bits (16 bytes)
  • Additional Auth Data: "WH-Encryption-v1" for integrity verification

Key Derivation

  • Algorithm: PBKDF2 with HMAC-SHA256
  • Iterations: 100,000 (configurable)
  • Salt: "encryption-salt" (default, configurable)
  • Output: 256-bit derived key

Data Format

All encrypted data follows this format (Base64 encoded):

[IV: 12 bytes] + [Auth Tag: 16 bytes] + [Ciphertext: variable]

Security Features

  • Authenticated Encryption: Prevents tampering and ensures data integrity
  • Random IV: Each encryption operation uses a cryptographically random IV
  • Key Separation: Different secret keys cannot decrypt each other's data
  • Format Validation: Strict validation of encrypted data structure
  • Cross-Platform Consistency: Identical security properties across all implementations

๐Ÿงช Testing & Validation

Run Tests

Node.js:

cd nodejs
npm test                    # Run unit tests
npm run test:coverage      # Generate coverage report
node test-compatibility.js # Cross-platform validation

C#:

cd csharp/csharp
dotnet run                 # Run test program with cross-platform vectors
dotnet test               # Run unit tests (if available)

Cross-Platform Compatibility Testing

The library includes comprehensive compatibility tests that verify:

  • Data encrypted by Node.js can be decrypted by C#
  • Data encrypted by C# can be decrypted by Node.js
  • Security features work consistently across platforms
  • Performance characteristics are acceptable

Example output:

๐Ÿ”„ Testing C# โ†” Node.js Compatibility
=====================================
โœ… All compatibility tests PASSED!
โœ… Cross-platform data exchange is working correctly
โœ… Security features are functioning properly
๐Ÿš€ Ready for production use!

๐Ÿ“ˆ Performance

Typical performance characteristics:

  • Node.js: ~20-30 operations/second for 1KB payloads
  • C#: ~40-50 operations/second for 1KB payloads
  • Browser: ~15-25 operations/second for 1KB payloads
  • Memory: Minimal memory footprint with proper disposal

๐Ÿ”„ CI/CD Workflows

The repository includes comprehensive GitHub Actions workflows:

Node.js CI (nodejs-ci.yml)

  • Multi-version testing: Node.js 16, 18, 20
  • Security auditing: npm audit with vulnerability checks
  • Cross-platform: Windows, macOS, Linux
  • Automated publishing: NPM package deployment
  • Coverage reporting: Code coverage analysis

C# CI (csharp-ci.yml)

  • Multi-framework: .NET 6.0, .NET 8.0
  • Cross-platform: Windows, macOS, Linux
  • NuGet publishing: Automated package deployment
  • Security scanning: Vulnerability assessment
  • Compatibility testing: Cross-platform validation

๐Ÿค Contributing

Development Guidelines

  1. Maintain Compatibility: Ensure changes don't break cross-platform compatibility
  2. Add Tests: Include comprehensive tests for new features
  3. Follow Patterns: Use established code patterns in each language
  4. Security First: Follow security best practices
  5. Documentation: Update documentation for API changes

Testing Workflow

  1. Make changes in one implementation
  2. Run local tests: npm test or dotnet run
  3. Run cross-platform tests: node test-compatibility.js
  4. Verify CI passes for both platforms
  5. Update documentation if needed

Code Style

  • Node.js: Follow existing JavaScript patterns, use TypeScript definitions
  • C#: Follow Microsoft C# coding conventions, use XML documentation
  • Both: Comprehensive error handling and input validation

๐Ÿ“‹ Version History

See CHANGELOG.md for detailed version history and migration guides.

๐Ÿ“„ License

MIT License Copyright ยฉ 2025 Duong Tran Quang. All rights reserved.

๐Ÿ‘ฅ Authors & Maintainers

Author: Duong Tran Quang Email: baymax.contact@gmail.com GitHub: https://github.com/DTDucas

๐Ÿ†˜ Support

For technical support, bug reports, or feature requests:

  1. Check existing documentation and examples
  2. Review the test files for usage patterns
  3. Create an issue on GitHub or email baymax.contact@gmail.com
  4. Ensure you're using the latest version

This encryption library is designed to work seamlessly with:

  • API services requiring secure data exchange
  • Frontend applications needing client-side encryption
  • Mobile applications with encryption requirements
  • Any application requiring cross-platform encryption

Note: This is an open source library available for use in any project under the MIT license.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 124 8/17/2025

v1.0.0 - Initial Release
     ========================
     โ€ข AES-256-GCM authenticated encryption with integrity verification
     โ€ข PBKDF2 key derivation with 100,000 iterations and SHA-256
     โ€ข Full cross-platform compatibility with Node.js implementation
     โ€ข Support for .NET 6.0+ and .NET 8.0+ with conditional compilation
     โ€ข Comprehensive security validation (tampering detection, key separation)
     โ€ข High-performance encryption/decryption with proper resource disposal
     โ€ข Complete API documentation and cross-platform test suite
     โ€ข Designed with enterprise-grade security standards