KeyRotation 1.1.1
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Core 2.1
This package targets .NET Core 2.1. The package is compatible with this framework or higher.
.NET Framework 4.5
This package targets .NET Framework 4.5. The package is compatible with this framework or higher.
dotnet add package KeyRotation --version 1.1.1
NuGet\Install-Package KeyRotation -Version 1.1.1
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="KeyRotation" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KeyRotation" Version="1.1.1" />
<PackageReference Include="KeyRotation" />
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 KeyRotation --version 1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: KeyRotation, 1.1.1"
#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 KeyRotation@1.1.1
#: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=KeyRotation&version=1.1.1
#tool nuget:?package=KeyRotation&version=1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Supported Frameworks
- .NET Framework 4.5, 4.6, 4.8
- .NET Core 2.1, 3.1
- .NET 5, 6, 7, 8
Installation
Install the package via NuGet Package Manager:
dotnet add package KeyRotation
Or via Package Manager Console:
Install-Package KeyRotation
Usage
Basic Usage
using KeyRotation;
// Encrypt an API key with current UTC date
string apiKey = "your-api-key-here";
string encryptedKey = KeyRotationHelper.EncryptApiKey(apiKey);
Console.WriteLine($"Encrypted Key: {encryptedKey}");
Advanced Usage
using KeyRotation;
using System;
// Encrypt with specific UTC date
DateTime specificDate = new DateTime(2024, 1, 15, 0, 0, 0, DateTimeKind.Utc);
string apiKey = "your-api-key-here";
string encryptedKey = KeyRotationHelper.EncryptApiKey(apiKey, specificDate);
// Validate encrypted key
bool isValid = KeyRotationHelper.ValidateApiKey(apiKey, encryptedKey, specificDate);
Console.WriteLine($"Key is valid: {isValid}");
// Validate with time tolerance (±5 minutes) to handle server/client time differences
bool isValidWithTolerance = KeyRotationHelper.ValidateApiKey(apiKey, encryptedKey, 5);
Console.WriteLine($"Key is valid with tolerance: {isValidWithTolerance}");
// Validate with specific date and tolerance
bool isValidWithSpecificTolerance = KeyRotationHelper.ValidateApiKey(apiKey, encryptedKey, specificDate, 10);
Console.WriteLine($"Key is valid with 10-minute tolerance: {isValidWithSpecificTolerance}");
// Get date string for specific date
string dateString = KeyRotationHelper.GetDateString(specificDate);
Console.WriteLine($"Date string: {dateString}"); // Output: 20240115
Example
API Reference
EncryptApiKey(string apiKey)
Encrypts an API key using the current UTC date.
Parameters:
apiKey
(string): The API key to encrypt
Returns: SHA256 hash as a hexadecimal string
Exceptions:
ArgumentNullException
: When apiKey is nullArgumentException
: When apiKey is empty or whitespace
EncryptApiKey(string apiKey, DateTime utcDateTime)
Encrypts an API key using a specific UTC date.
Parameters:
apiKey
(string): The API key to encryptutcDateTime
(DateTime): The UTC datetime to use for encryption
Returns: SHA256 hash as a hexadecimal string
Exceptions:
ArgumentNullException
: When apiKey is nullArgumentException
: When apiKey is empty or whitespace
ValidateApiKey(string apiKey, string encryptedKey)
Validates an encrypted API key against the current UTC date.
Parameters:
apiKey
(string): The original API keyencryptedKey
(string): The encrypted key to validate
Returns: true
if valid, false
otherwise
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. 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 is compatible. 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. |
.NET Core | netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Framework | net45 is compatible. net451 was computed. net452 was computed. net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 2.1
- No dependencies.
-
.NETCoreApp 3.1
- No dependencies.
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.6
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.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 |
---|---|---|
1.1.1 | 16 | 8/26/2025 |