EggEgg.XC.RSAUtil 136.1.1

dotnet add package EggEgg.XC.RSAUtil --version 136.1.1                
NuGet\Install-Package EggEgg.XC.RSAUtil -Version 136.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="EggEgg.XC.RSAUtil" Version="136.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EggEgg.XC.RSAUtil --version 136.1.1                
#r "nuget: EggEgg.XC.RSAUtil, 136.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.
// Install EggEgg.XC.RSAUtil as a Cake Addin
#addin nuget:?package=EggEgg.XC.RSAUtil&version=136.1.1

// Install EggEgg.XC.RSAUtil as a Cake Tool
#tool nuget:?package=EggEgg.XC.RSAUtil&version=136.1.1                

EN | δΈ­ζ–‡

Notice

This package is not the official version of GitHub Repository stulzq/RSAUtil but a custom fork. Please go to NuGet XC.RSAUtil for the official one.

RSAUtil

A .NET Core RSA tool that provides the ability of data encryption, decryption, signing and verifying signature. It supports using and converting RSA keys of formats, namely: .xml, .pem, .der.

Latest version

Installation via NuGet

Install-Package EggEgg.XC.RSAUtil

Documentation

What are the special features of this fork?

  • The RSAUtilBase.LoadRSAKey(byte[]) method can easily load any supported format of private and public keys, automatically detecting the format, key size, and other parameters, so you don't need to worry about the underlying details of RSA operations.
  • (compared to the original version) Added comprehensive support for PKCS#1 RSA public keys.
  • Supports the .der binary key format.
  • Together with the RsaKeyFeature class and the RSAUtilBase.TreatRSAKeyType(byte[]) method, compared to the original implementation's hard-coded approach, you can more flexibly handle RSA key operations.
  • Added unit tests to ensure the correctness of the package's behavior.

Generating keys

Use the "RsaKeyGenerator" class. The result returned is a BinaryKeyResult containing KeySize, Format, Padding, PrivateKey and PublicKey.

Like this:

var keys = RsaKeyGenerator.GetKey(RsaKeyFormat.Pem, RsaKeyPadding.Pkcs1, 2048);
// or use RsaKeyFeature class
// var keys = RsaKeyGenerator.GetKey(new RsaKeyFeature { Format = RsaKeyFormat.Der, Padding = RsaKeyPadding.Pkcs1 }, 2048);

byte[] privateKey = keys.PrivateKey;
byte[] publicKey = key.PublicKey;
// You can directly use it also:
var rsa = keys.GetRSAInstance();
// Or save key and load next time:
rsa = RSAUtilBase.LoadRSAKey(privateKey);

RSA key conversion

You can freely convert key formats using RsaKeyConvert.Format(). For example:

RsaKeyConvert.Format(key,
    new RsaKeyFeature { IsPrivate = true; Format = RsaKeyFormat.Der; Padding = RsaKeyPadding.Pkcs1 });

RsaKeyConvert.Format(key,
    new RsaKeyFeature { IsPrivate = false; Format = RsaKeyFormat.Pem; Padding = RsaKeyPadding.Pkcs1 });

RsaKeyConvert.Format(key,
    new RsaKeyFeatire { IsPrivate = false; Format = RsaKeyFormat.Pem; Padding = RsaKeyPadding.Pkcs8 });

You can also use RSAUtilBase's instance method FormatPublicKey or FormatPrivateKey to export the key of any RSA instance, in any format you want.

var rsa = RsaKeyGenerator.GetKey(RsaKeyFormat.Pem, RsaKeyPadding.Pkcs1, 2048).GetRSAInstance();
rsa.FormatPublicKey(new RsaKeyFeature { IsPrivate = false; Format = RsaKeyFormat.Xml; Padding = RsaKeyPadding.Xml });
rsa.FormatPrivateKey(new RsaKeyFeatire { IsPrivate = false; Format = RsaKeyFormat.Pem; Padding = RsaKeyPadding.Pkcs8 });
rsa.FormatPrivateKey(new RsaKeyFeature { IsPrivate = true; Format = RsaKeyFormat.Der; Padding = RsaKeyPadding.Pkcs1 });

Encryption, decryption, signing, and signature verification

Load any key via RSAUtilBase.LoadRSAKey(byte[]), then:

  • Encryption: RSAUtilBase.RsaEncrypt()
  • Decryption: RSAUtilBase.RsaDecrypt()
  • Sign: RSAUtilBase.SignData()
  • Verification: RSAUtilBase.VerifyData()

Open-source components used

bc-csharp - onovotny

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
136.1.1 198 7/29/2024
136.1.0 116 6/24/2024
136.0.0 371 12/11/2023

Notice: This package is not the official version of GitHub Repository stulzq/RSAUtil but a custom modified version. Please go to XC.RSAUtil for the official one.