PublicKeyUtils 10.0.0

dotnet add package PublicKeyUtils --version 10.0.0
                    
NuGet\Install-Package PublicKeyUtils -Version 10.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="PublicKeyUtils" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PublicKeyUtils" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="PublicKeyUtils" />
                    
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 PublicKeyUtils --version 10.0.0
                    
#r "nuget: PublicKeyUtils, 10.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 PublicKeyUtils@10.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=PublicKeyUtils&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=PublicKeyUtils&version=10.0.0
                    
Install as a Cake Tool

PublicKeyUtils

NuGet Version NuGet Downloads License: MIT Build Status

PublicKeyUtils is an open-source .NET class library designed to simplify working with public keys for cryptographic operations. It provides utilities for encryption, decryption, signing, and verification using public keys. The library is built with extensibility and ease of use in mind, making it a great choice for developers working with RSA and ECC cryptography.

Table of Contents

Features

  • RSA Public Key Operations:

    • Encrypt data using RSA public keys with support for various padding schemes (RSA-OAEP with SHA-1, SHA-256, SHA-384, SHA-512)
    • Decode and parse RSA public key components (modulus and exponent) from Base64URL-encoded strings
    • Key operation validation to ensure encryption is only performed when allowed
  • ECC Public Key Operations:

    • Verify digital signatures using ECC public keys
    • Support for named curves such as P-256, P-384, and P-521
    • Hash algorithm support for SHA-1, SHA-256, SHA-384, and SHA-512
  • JSON Serialization:

    • Public key properties are annotated with System.Text.Json.Serialization attributes for seamless JSON serialization and deserialization
    • Compatible with JWK (JSON Web Key) format
  • Unit Tests:

    • Comprehensive test coverage using xUnit to ensure correctness and reliability
    • All cryptographic operations thoroughly tested

Installation

The library is available as a NuGet package. You can install it using one of the following methods:

.NET CLI

dotnet add package PublicKeyUtils

Package Manager Console

Install-Package PublicKeyUtils

Package Reference

<PackageReference Include="PublicKeyUtils" Version="*" />

For more details, visit the NuGet package page.

Usage Examples

RSA Encryption

Encrypt data using an RSA public key with different padding schemes:

using PublicKeyUtils.CryptoKeys;

// Create an RSA public key for encryption
var publicKey = new EncryptDecryptPublicKey
{
    Algorithm = "RSA-OAEP-256",  // Use RSA-OAEP with SHA-256
    E = "AQAB",  // Public exponent (65537)
    N = "sXch9W6_K8oZn3PfJPZepKvXYTwc_nPIu9JrYfPRzM8zqVnD3edGldHTebAiN4MbcDkN5q1nbRV69BQ1_lwPt6b92_l6dcH0QJebQqovExY16Y7bQO02NGqjc8tkFPAeqC1cgI2VmojzG3FeAWqxtj5Ez5g0PYYJgxIoEXRopv9N2V-DME4mXwMxf3NVZ9d73Sm1Tb9p_U1OwQuWCh0p4kJHDsh44yBdM37KMLWSLM6pEr7jeWyzX0d1sKdfbORaVq0f1uzjZ_3iM_Oey7GMJKkPGYQlQjWbL2iyHv5PeAxJmZLykB0CZ0oUzOGlYfKJhL1x_j1D_zFckvj7o0K9GQ",  // Modulus (Base64URL)
    KeyOps = new[] { "encrypt" }  // Allowed operations
};

// Encrypt plaintext
string plaintext = "Hello, World!";
byte[] ciphertext = publicKey.Encrypt(plaintext);

Console.WriteLine($"Encrypted data: {Convert.ToBase64String(ciphertext)}");

Supported RSA Padding Schemes:

  • RSA-OAEP - RSA-OAEP with SHA-1
  • RSA-OAEP-256 - RSA-OAEP with SHA-256
  • RSA-OAEP-384 - RSA-OAEP with SHA-384
  • RSA-OAEP-512 - RSA-OAEP with SHA-512

ECC Signature Verification

Verify digital signatures using an ECC public key:

using PublicKeyUtils.CryptoKeys;

// Create an ECC public key for signature verification
var publicKey = new SignVerifyPublicKey
{
    Algorithm = "ES256",  // ECDSA with SHA-256
    Curve = "P-256",      // Named curve
    X = "WKn-ZIGevcwGIyyrzFoZNBdaq9_TsqzGl96oc0CWuis",  // X coordinate (Base64URL)
    Y = "y77t-RvAHRKTsSGdIYUfweuOvwrvDD-Q3Hv5J0fSKbE",  // Y coordinate (Base64URL)
    KeyOps = new[] { "verify" }  // Allowed operations
};

// Data and signature to verify
string data = "Important message";
byte[] signature = Convert.FromBase64String("MEUCIQDKZokqnCjrRtw0...");

// Verify the signature
bool isValid = publicKey.Verify(data, signature);

Console.WriteLine($"Signature valid: {isValid}");

Supported ECC Algorithms:

  • ES256 - ECDSA with SHA-256
  • ES384 - ECDSA with SHA-384
  • ES512 - ECDSA with SHA-512

Supported Algorithms

RSA Encryption Padding Schemes

Algorithm Description Hash Function
RSA-OAEP RSA-OAEP padding SHA-1
RSA-OAEP-256 RSA-OAEP padding SHA-256
RSA-OAEP-384 RSA-OAEP padding SHA-384
RSA-OAEP-512 RSA-OAEP padding SHA-512

ECC Curves

Curve Key Size Description
P-256 256-bit NIST P-256 (secp256r1)
P-384 384-bit NIST P-384 (secp384r1)
P-521 521-bit NIST P-521 (secp521r1)

Hash Algorithms

  • SHA-1 (legacy support)
  • SHA-256 (recommended)
  • SHA-384
  • SHA-512

Contributing

Contributions are welcome! If you have ideas for new features, bug fixes, or improvements, feel free to:

  1. Open an Issue: Report bugs or suggest features on the GitHub Issues page
  2. Submit a Pull Request: Fork the repository, make your changes, and submit a PR
  3. Improve Documentation: Help enhance the documentation and examples

Please ensure all tests pass before submitting a pull request:

dotnet test

CI/CD

This project uses GitHub Actions for continuous integration and deployment. On every push to a version tag (e.g., v2.0.0), the library is automatically:

  • Built and tested
  • Packaged as a NuGet package
  • Published to NuGet.org

See the release workflow for more details.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

Special thanks to all contributors and the open-source community for their support and feedback.


Links:

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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
10.0.0 188 11/26/2025
3.0.0 291 4/13/2025
2.0.1 168 4/13/2025
1.0.1 182 4/12/2025
1.0.0 172 4/12/2025