WH.Encryption
1.0.0
dotnet add package WH.Encryption --version 1.0.0
NuGet\Install-Package WH.Encryption -Version 1.0.0
<PackageReference Include="WH.Encryption" Version="1.0.0" />
<PackageVersion Include="WH.Encryption" Version="1.0.0" />
<PackageReference Include="WH.Encryption" />
paket add WH.Encryption --version 1.0.0
#r "nuget: WH.Encryption, 1.0.0"
#:package WH.Encryption@1.0.0
#addin nuget:?package=WH.Encryption&version=1.0.0
#tool nuget:?package=WH.Encryption&version=1.0.0
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 modulecreateBrowserEncryption()
- 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
- Maintain Compatibility: Ensure changes don't break cross-platform compatibility
- Add Tests: Include comprehensive tests for new features
- Follow Patterns: Use established code patterns in each language
- Security First: Follow security best practices
- Documentation: Update documentation for API changes
Testing Workflow
- Make changes in one implementation
- Run local tests:
npm test
ordotnet run
- Run cross-platform tests:
node test-compatibility.js
- Verify CI passes for both platforms
- 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:
- Check existing documentation and examples
- Review the test files for usage patterns
- Create an issue on GitHub or email baymax.contact@gmail.com
- Ensure you're using the latest version
๐ Related Projects
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 | Versions 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. |
-
net6.0
- System.Text.Json (>= 8.0.5)
-
net8.0
- System.Text.Json (>= 8.0.5)
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