Ckode.Encryption 2.1.0

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

// Install Ckode.Encryption as a Cake Tool
#tool nuget:?package=Ckode.Encryption&version=2.1.0

Ckode.Encryption

Ckode.Encryption is a small collection of simplified wrappers for common encryption algorithms.

Currently supports the following algorithms:

  • AES
  • AES with a string password used as encryption key
  • RSA

All algorithms are from the .NET library.

The AES and RSA classes both offer a GenerateKey or GenerateKeyPair method which should be used to generate new keys (do not roll your own key generator, it'll probably have insecurities)

Installation:

I recommend using the NuGet package: https://www.nuget.org/packages/Ckode.Encryption/ however you can also simply clone the repository and use the pre-compiled binaries or compile the project yourself. As the project is licensed under MIT you're free to use it for pretty much anything you want.

Examples:

Encrypt a file with AES:

var aes = new Ckode.Encryption.AES();
var key = aes.GenerateKey(); // Make sure to store the key somewhere for decryption later on

var rawBytes = File.ReadAllBytes(filePath);
var encrypted = aes.Encrypt(rawBytes, key);
File.WriteAllBytes(encryptedFilePath, encrypted);

Encrypt a string with AES, using a password as key:

var aes = new Ckode.Encryption.AESWithPassword();
var key = "My secret";

var rawString = "Something nobody but me should read";
var encryptedString = aes.Encrypt(rawString, Encoding.UTF8, key);

// To decrypt:
var decryptedString = aes.Decrypt(encryptedString, Encoding.UTF8, key);

Encrypt a file with RSA:

var rsa = new Ckode.Encryption.RSA();
var keyPair = rsa.GenerateKeyPair(); // Make sure to store the key pair, and keep the private key private.

var rawBytes = File.ReadAllBytes(filePath);
var encrypted = rsa.Encrypt(rawBytes, keyPair);
File.WriteAllBytes(encryptedFilePath, encrypted);

// To decrypt
rsa.Decrypt(encrypted, keyPair);
// or
rsa.Decrypt(encrypted, keyPair.PrivateKey);
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.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.1.0 201 11/6/2023
2.0.0 391 3/12/2021
1.0.4 1,031 3/20/2018
1.0.3 903 3/20/2018
1.0.2 922 3/18/2018
1.0.1 901 3/11/2018
1.0.0 919 3/11/2018