SH.Framework.Library.Generators 1.0.0

There is a newer version of this package available.
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
                    
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="SH.Framework.Library.Generators" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SH.Framework.Library.Generators" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SH.Framework.Library.Generators" />
                    
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 SH.Framework.Library.Generators --version 1.0.0
                    
#r "nuget: SH.Framework.Library.Generators, 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 SH.Framework.Library.Generators@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=SH.Framework.Library.Generators&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SH.Framework.Library.Generators&version=1.0.0
                    
Install as a Cake Tool

SH Framework - Generators Library

NuGet Version NuGet Downloads License: MIT

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
1.1.0 61 8/23/2025
1.0.1 57 8/22/2025
1.0.0 58 8/22/2025