u9sharp 1.0.0

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

u9sharp

u9 cryptography library for C#.

Currently supports only RSA_OAEP but I will implement AES algorithm and TLS protocol.

Supports

  • RSA_OAEP with SHA-1 and MGF-1
  • RSA key generation
  • DER encoded key import/export
  • RSA Encryption/Decryption
  • OpenSSH style RandomArt generation
  • AES Encryption/Decryption (soon)
  • TLS protocol (soon)
Demo Project

Basic Usage

For encryption/decryption:

using System.Text;
using u9sharp;

...

// generate a new key with modulus length 1024
RSAPrivateKey privateKey = new RSAPrivateKey(1024);

// export DER encoded ASN.1 keys
privateKey.Export("prv.pem");
privateKey.GetPublicKey().Export("pub.pem");

// create engine for encryption/decryption
RSAEngine engine = new RSAEngine(privateKey);

// some data to encrypt
byte[] data = Encoding.UTF8.GetBytes("test");

// encrypt data with null label (new byte[0])
byte[] cipher = engine.Encrypt(data, null, RSAEncryptionScheme.OAEP);

// decrypt
byte[] output = engine.Decrypt(data, null, RSAEncryptionScheme.OAEP);

// write output (should be "test")
Console.WriteLine("Out: {0}", Encoding.UTF8.GetString(output));

You can use the Prime class to generate pseudo-primes. It uses the Rabin-Miller algorithm with 10 rounds by default:

using System.Numerics;
using u9sharp;

...

// generate a 512-bit pseudo-prime
BigInteger pprime = Prime.random_prime(512);

// you can change the number of rounds. for example:
Prime.round_num = 15;

Or you can use the MGF-1 implementation:

using System.Text;
using u9sharp;

...

// mask seed "foo" with length 5
byte[] mask = Masking.MGF1(Encoding.UTF8.GetBytes("foo"), 5, Helper.HashSHA1);

// output the result. (should be "1ac9075cd4")
Console.WriteLine("Out: {0}", Convert.ToHexString(mask).ToLower());

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.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.0.0 257 2/13/2023