SecureTokenGeneratR 2.0.0-alpha.1
dotnet add package SecureTokenGeneratR --version 2.0.0-alpha.1
NuGet\Install-Package SecureTokenGeneratR -Version 2.0.0-alpha.1
<PackageReference Include="SecureTokenGeneratR" Version="2.0.0-alpha.1" />
<PackageVersion Include="SecureTokenGeneratR" Version="2.0.0-alpha.1" />
<PackageReference Include="SecureTokenGeneratR" />
paket add SecureTokenGeneratR --version 2.0.0-alpha.1
#r "nuget: SecureTokenGeneratR, 2.0.0-alpha.1"
#:package SecureTokenGeneratR@2.0.0-alpha.1
#addin nuget:?package=SecureTokenGeneratR&version=2.0.0-alpha.1&prerelease
#tool nuget:?package=SecureTokenGeneratR&version=2.0.0-alpha.1&prerelease
SecureTokenGeneratR
SecureTokenGeneratR generates random tokens using .NET's cryptographically secure random number generator. It has no external dependencies.
Install
dotnet add package SecureTokenGeneratR
Defaults
By default, generated tokens:
- Are 16 characters long.
- Include at least one character from each set: lowercase letters, uppercase letters, digits, and ASCII punctuation.
- Have no limit on repeated characters.
Usage
Default generator
Use SecureToken.Default to generate tokens with the default settings:
using SecureTokenGeneratR;
string token = SecureToken.Default.Generate();
Fluent configuration
Each call returns a new generator, so options can be chained:
| Call | Effect |
|---|---|
SecureToken.Default |
Starts with the default length and character sets. |
WithLength(length) |
Sets a fixed token length. |
WithLength(minimum, maximum) |
Randomly chooses an inclusive length between minimum and maximum for each generated token. |
WithMaxRepeatingCharCount(count) |
Limits how many times any one character may appear; 0 means no limit. |
AddCharset(sequence) |
Adds a character sequence to the current allowed sets. When called on SecureToken, starts with the default sets. |
AddCharset(start, end) |
Adds an inclusive Unicode range to the current allowed sets. When called on SecureToken, starts with the default sets. |
ReplaceCharsets(sequence) |
Replaces all current allowed sets with one character sequence. |
ReplaceCharsets(start, end) |
Replaces all current allowed sets with one inclusive Unicode range. |
ReplaceCharsets(charsets) |
Replaces all current allowed sets with the supplied ICharacterSet collection. |
Generate() |
Generates a token using the configured options. |
AddCharset adds; ReplaceCharsets replaces. Generated tokens include at least one character from each configured set.
For example, this generator adds two sets and picks a random token length from 8 to 24. The second generator replaces those sets with digits:
using SecureTokenGeneratR;
var generator = SecureToken.AddCharset("%XW-[]{}") // character sequence
.AddCharset('A', 'F') // inclusive Unicode range: U+0041 to U+0046
.WithLength(8, 24)
.WithMaxRepeatingCharCount(2);
string token = generator.Generate();
var digitsOnlyGenerator = generator.ReplaceCharsets('0', '9');
For multiple custom sets, construct each with CharacterSet and pass them to ReplaceCharsets:
using SecureTokenGeneratR.CharacterSets;
ICharacterSet[] charsets =
[
new CharacterSet("abc"), // character sequence
new CharacterSet('0', '9') // inclusive Unicode range: U+0030 to U+0039
];
var customGenerator = SecureToken.Default.ReplaceCharsets(charsets);
Entropy
The generator exposes estimates for token entropy and per-character entropy:
var generator = SecureToken.Default;
string token = generator.Generate();
double tokenEntropy = generator.GetTokenEntropy;
double characterEntropy = generator.GetCharacterEntropy(token);
Entropy is one measure of strength and should not be used as the only security assessment.
Compatibility
Targets .NET Framework 4.6.1, .NET Standard 2.0 and 2.1, and .NET 6, 8, and 10.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. 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 is compatible. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.1
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net10.0
- No dependencies.
-
net6.0
- No dependencies.
-
net8.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 |
|---|---|---|
| 2.0.0-alpha.1 | 0 | 10/24/2026 |
| 1.0.1 | 37,220 | 10/17/2021 |
| 1.0.0 | 756 | 10/10/2021 |
* First alpha release of 2.0.0