CryptoNet 1.2.0
See the version list below for details.
dotnet add package CryptoNet --version 1.2.0
NuGet\Install-Package CryptoNet -Version 1.2.0
<PackageReference Include="CryptoNet" Version="1.2.0" />
paket add CryptoNet --version 1.2.0
#r "nuget: CryptoNet, 1.2.0"
// Install CryptoNet as a Cake Addin #addin nuget:?package=CryptoNet&version=1.2.0 // Install CryptoNet as a Cake Tool #tool nuget:?package=CryptoNet&version=1.2.0
Introdution
CryptoNet is a simple and a lightweight asymmetric encryption NuGet library. It is a 100% native C# implementation based on RSA factory class.
Installation
You can download CryptoNet via NuGet.
Versions
is latest version and are maintained.
v1.2.0 (Breaking changes)
- Change from RSACryptoServiceProvider to RSA factory.
- No longer support for symmertic encryption.
- Console examples and Unit testing refactored.
- Support for X509Certificate2.
v1.0.0:
- Ability to encrypt and decrypt files like, images, word, excel etc.
- Improvement documentation
Issues
Please report issues here.
Using / Documentation
Short intro
The are 2 ways to encrypt and decrypt content:
- Asymmetric RSA key pair (self generated keys).
- Asymmetric X509 Certificate (use own certificate).
Both ways:
- Have a Private and Public key.
- Use Public key to encrypt.
- Use Private key to decrypt.
- For RSA way, 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 Content With SelfGenerated AsymmetricKey
ICryptoNet cryptoNet = new CryptoNet();
var privateKey = cryptoNet.ExportPrivateKey();
var publicKey = cryptoNet.ExportPublicKey();
ICryptoNet encryptClient = new CryptoNet(publicKey);
var encrypt = encryptClient.EncryptFromString(ConfidentialDummyData);
Console.WriteLine($"1- We will encrypt following text:\n{ConfidentialDummyData}\n");
Console.WriteLine($"2- To:\n{CryptoNetUtils.BytesToString(encrypt)}\n");
ICryptoNet decryptClient = new CryptoNet(privateKey);
var decrypt = decryptClient.DecryptToString(encrypt);
Console.WriteLine($"3- And we will decrypt it back to:\n{decrypt}\n");
Example: Generate and Export Asymmetric Key (Private/Public) Key (RasKeyPair)
ICryptoNet cryptoNet = new CryptoNet();
CryptoNetUtils.SaveKey(PrivateKeyFile, cryptoNet.ExportPrivateKey());
CryptoNetUtils.SaveKey(PublicKeyFile, cryptoNet.ExportPublicKey());
var privateKey = CryptoNetUtils.LoadFileToString(PrivateKeyFile);
Console.WriteLine($"The private key generated and saved to file {PrivateKeyFile}");
Console.WriteLine(privateKey);
var publicKey = CryptoNetUtils.LoadFileToString(PublicKeyFile);
Console.WriteLine($"\nThe public key generated and saved to file {PublicKeyFile}");
Console.WriteLine(publicKey);
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);
Build and Testing
Build and run unit test from:
- Visual Studio 2019/2022.
- dotnet command line.
- Powershell, run build.ps1 from solution folder.
- Docker, run following command from solution folder:
docker build . --file .\Dockerfile --tag cryptonet-service:latest
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 | Versions 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. 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. |
.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. |
-
.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 | 26,292 | 9/27/2023 |