CryptoNet 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package CryptoNet --version 1.0.0
NuGet\Install-Package CryptoNet -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="CryptoNet" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CryptoNet --version 1.0.0
#r "nuget: CryptoNet, 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.
// Install CryptoNet as a Cake Addin
#addin nuget:?package=CryptoNet&version=1.0.0

// Install CryptoNet as a Cake Tool
#tool nuget:?package=CryptoNet&version=1.0.0

Cryptonet

CryptoNet NuGet version CryptoNet NuGet pre-release version Passing build workflow The Standard - COMPLIANT BCH compliance GitHub

Introdution

CryptoNet is a simple and a lightweight symmetric and asymmetric RSA encryption NuGet library. It is a 100% native C# implementation based on RSACryptoServiceProvider class.

Installation

You can download CryptoNet via NuGet.

Versions

Nuget is latest version and are maintained.

Issues

Please report issues here.

Using / Documentation

Short intro

There are 2 ways to encrypt and decrypt content:

  1. Symmetric way (By default):
    • Use same key to encrypt and decrypt.
  2. Asymmetric way
    • You have 2 keys, Private and Public key.
    • Use Public key to encrypt.
    • Use Private key to decrypt.
    • You need to generate RSA key pair first (Private/Public key).

You find the comlete and all examples here.

Here is some of the examples:

Example: Encrypt and Decrypt with Symmetric Key

ICryptoNet encryptClient = new CryptoNet(SymmetricKey);
Console.WriteLine("1- We will encrypt following:");
Console.WriteLine(ConfidentialDummyData);

var encrypted = encryptClient.EncryptFromString(ConfidentialDummyData);
Console.WriteLine("2- To:");
Console.WriteLine(CryptoNetUtils.BytesToString(encrypted));

ICryptoNet decryptClient = new CryptoNet(SymmetricKey);
var decrypted = decryptClient.DecryptToString(encrypted);
Console.WriteLine("3- And we will decrypt it back with correct key:");
Console.WriteLine(decrypted);

ICryptoNet decryptClientWithWrongKey = new CryptoNet("wrong key");
var decryptWithWrongKey = decryptClientWithWrongKey.DecryptToString(encrypted);
Console.WriteLine("4- And we will not be able decrypt it back with wrong key:");
Console.WriteLine(decryptWithWrongKey);

Example: Generate and Export Asymmetric Key (Private/Public) Key (RasKeyPair)

ICryptoNet cryptoNet = new CryptoNet("My-Secret-Key");

CryptoNetUtils.SaveKey(PrivateKeyFile, cryptoNet.ExportPrivateKey());
CryptoNetUtils.SaveKey(PublicKeyFile, cryptoNet.ExportPublicKey());

var certificate = CryptoNetUtils.LoadFileToString(PrivateKeyFile);
var publicKey = CryptoNetUtils.LoadFileToString(PublicKeyFile);

Example: Encrypt with Public Key and later Decrypt with Private Key

var certificate = CryptoNetUtils.LoadFileToString(RsaKeyPair);
// Export public key
ICryptoNet cryptoNet = new CryptoNet(certificate, true);
var publicKey = cryptoNet.ExportPublicKey();
CryptoNetUtils.SaveKey(PublicKeyFile, publicKey);

// Import public key and encrypt
var importPublicKey = CryptoNetUtils.LoadFileToString(PublicKeyFile);
ICryptoNet cryptoNetEncryptWithPublicKey = new CryptoNet(importPublicKey, true);
var encryptWithPublicKey = cryptoNetEncryptWithPublicKey.EncryptFromString(ConfidentialDummyData);
Console.WriteLine("1- This time we use a certificate public key to encrypt");
Console.WriteLine(CryptoNetUtils.BytesToString(encryptWithPublicKey));

ICryptoNet cryptoNetDecryptWithPublicKey = new CryptoNet(certificate, true);
var decryptWithPrivateKey = cryptoNetDecryptWithPublicKey.DecryptToString(encryptWithPublicKey);
Console.WriteLine("6- And use the same certificate to decrypt");
Console.WriteLine(decryptWithPrivateKey);

Contributing

I need your help, so if you have good knowledge of C# and Cryptography just grab one of the issues and add a pull request. The same is valid, if you have idea for improvement or adding new feature.

How to contribute:

Here is a link to learn how to contribute if you are not a ware of how to do it.

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 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. 
.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 was computed. 
.NET Framework net461 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.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.4.0 2,264 9/27/2023
2.3.0 581 8/15/2023
2.2.0 6,244 10/28/2022
2.2.0-preview001 117 7/12/2022
2.1.0 1,743 5/21/2022
1.6.0 432 2/3/2022
1.5.0 217 1/9/2022
1.2.0 209 1/1/2022
1.0.0 214 12/24/2021