SH.Framework.Library.Generators
1.0.0
See the version list below for details.
dotnet add package SH.Framework.Library.Generators --version 1.0.0
NuGet\Install-Package SH.Framework.Library.Generators -Version 1.0.0
<PackageReference Include="SH.Framework.Library.Generators" Version="1.0.0" />
<PackageVersion Include="SH.Framework.Library.Generators" Version="1.0.0" />
<PackageReference Include="SH.Framework.Library.Generators" />
paket add SH.Framework.Library.Generators --version 1.0.0
#r "nuget: SH.Framework.Library.Generators, 1.0.0"
#:package SH.Framework.Library.Generators@1.0.0
#addin nuget:?package=SH.Framework.Library.Generators&version=1.0.0
#tool nuget:?package=SH.Framework.Library.Generators&version=1.0.0
SH Framework - Generators Library
A secure character and code generator library for .NET applications. Provides cryptographically secure random string generation with support for alphabetic, numeric, alphanumeric, and symbol character sets with customizable formats and patterns.
Features
- Cryptographically Secure: Uses
RandomNumberGenerator
for secure random generation - Multiple Character Types: Support for alphabetic, numeric, alphanumeric, and symbol characters
- Custom Character Sets: Combine multiple character types or provide custom character sets
- Formatted Code Generation: Generate codes with specific patterns using format strings
- High Performance: Optimized for speed and memory efficiency
- Thread Safe: Safe for use in multi-threaded applications
Installation
Install the package via NuGet Package Manager:
dotnet add package SH.Framework.Library.Generators
Or via Package Manager Console:
Install-Package SH.Framework.Library.Generators
Quick Start
using SH.Framework.Library.Generators;
var generator = new CharacterGenerator();
// Generate a 6-character alphanumeric code (default)
var code = generator.Generate();
// Output: "A7xK9m"
// Generate a 10-character numeric code
var numericCode = generator.GenerateNumericCode(10);
// Output: "4729581063"
// Generate with specific character type
var alphabetic = generator.Generate(8, CharacterType.Alphabet);
// Output: "KmPqRsXz"
Usage Examples
Basic Generation
var generator = new CharacterGenerator();
// Default: 6 characters, alphanumeric
var defaultCode = generator.Generate();
// Specify length and character type
var customCode = generator.Generate(12, CharacterType.Alphanumeric);
// Numeric codes (useful for verification codes)
var verificationCode = generator.GenerateNumericCode(6);
Multiple Character Types
// Combine multiple character types
var mixedCode = generator.Generate(10,
CharacterType.Alphabet,
CharacterType.Numeric,
CharacterType.Symbol);
// This will include letters, numbers, and symbols
Custom Character Sets
// Use custom character sets
var customCode = generator.Generate(8, "ABCDEF", "123456");
// Will only use characters A-F and numbers 1-6
// Vowels only
var vowelCode = generator.Generate(6, "AEIOU");
Formatted Code Generation
Generate codes with specific patterns using format strings:
// Format characters:
// A = Any alphabet character (upper or lower case)
// N = Any numeric character
// B = Any alphanumeric character
// L = Any alphabet character (lowercase only)
// S = Any symbol character
// Any other character = literal character
var formattedCode = generator.GenerateFormattedCode("AAA-NNN");
// Output: "KmP-847"
var licenseKey = generator.GenerateFormattedCode("AAAA-BBBB-NNNN");
// Output: "XYZW-A7B9-1234"
var strongPassword = generator.GenerateFormattedCode("LLLLSSNNN");
// Output: "abcd!@123"
Advanced Examples
// Generate a secure API key
var apiKey = generator.Generate(32, CharacterType.Alphanumeric);
// Generate a temporary password with symbols
var tempPassword = generator.Generate(12,
CharacterType.Alphabet,
CharacterType.Numeric,
CharacterType.Symbol);
// Generate a user-friendly code (no ambiguous characters)
var friendlyCode = generator.Generate(8, "ABCDEFGHJKLMNPQRSTUVWXYZ23456789");
// Generate a formatted product key
var productKey = generator.GenerateFormattedCode("AAAA-BBBB-CCCC-DDDD");
Character Types
Type | Characters | Use Case |
---|---|---|
Alphabet |
A-Z, a-z | Letters only |
Numeric |
0-9 | Numbers only (verification codes) |
Alphanumeric |
A-Z, a-z, 0-9 | General purpose codes |
Symbol |
!@#$%^&*()_+-=[]{}|;:,.<>? | Special characters |
Security Features
- Uses
System.Security.Cryptography.RandomNumberGenerator
for cryptographically secure randomness - No predictable patterns in generated strings
- Thread-safe implementation
- Memory-efficient generation process
Performance
The library is optimized for high-performance scenarios:
- Minimal memory allocations
- Efficient character set handling
- Fast random number generation
- Suitable for high-throughput applications
Requirements
- .NET 9.0 or higher
- No external dependencies (uses only .NET BCL)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Support
If you encounter any issues or have questions, please open an issue on GitHub.
SH Framework - Building robust .NET applications, one library at a time.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.