Ckode.Encryption
2.1.0
dotnet add package Ckode.Encryption --version 2.1.0
NuGet\Install-Package Ckode.Encryption -Version 2.1.0
<PackageReference Include="Ckode.Encryption" Version="2.1.0" />
paket add Ckode.Encryption --version 2.1.0
#r "nuget: Ckode.Encryption, 2.1.0"
// 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 | Versions 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. |
-
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.