SimpleEncrypt 1.0.1

dotnet add package SimpleEncrypt --version 1.0.1
                    
NuGet\Install-Package SimpleEncrypt -Version 1.0.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="SimpleEncrypt" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SimpleEncrypt" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="SimpleEncrypt" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SimpleEncrypt --version 1.0.1
                    
#r "nuget: SimpleEncrypt, 1.0.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.
#:package SimpleEncrypt@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SimpleEncrypt&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=SimpleEncrypt&version=1.0.1
                    
Install as a Cake Tool

SimpleEncrypt

SimpleEncrypt is a lightweight .NET library that implements symmetric encryption using a Diffie-Hellman key exchange. It allows two parties to securely encrypt and decrypt messages by generating a shared key.

Installation:

To integrate SimpleEncrypt into your project, you can install the NuGet package using either the NuGet Package Manager Console or the .NET CLI.

Usage:

Example of Using EncryptManager

The EncryptManager class handles key generation, key exchange, and message encryption/decryption.

Exanple:

using SimpleEncrypt;
class Program
{
	static void Main(string[] args)
        {
        	// Create two instances of EncryptManager (e.g., for two communication partners)
                EncryptManager encrypt = new EncryptManager(1024); // Key length in charakters

                // User1 sends their public key to User2 and vice versa
                string publicKey= encrypt.GetPublicKey();

		//Implement a function to get the public key of user 2 e.g with TcpClient
		//In this Example we just create a new EncryptManager to Simulate a second user
		EncryptManager user2 = new EncryptManager(1024);
		string publicKeyUser2 = user2.GetPublicKey(); 

        	// Initialize the shared key on both sides
        	encrypt.InitSharedKey(publicKeyUser2);

        	// Encrypt a message (from User1 to User2)
        	string message = "Secret message";
        	string encryptedMessage = encrypt.EncryptMessage(message);
        	Console.WriteLine($"Encrypted Message: {encryptedMessage}");

        	// Decrypt the message (on User2's side)
        	string decryptedMessage = encrypt.DecryptMessage(encryptedMessage);
        	Console.WriteLine($"Decrypted Message: {decryptedMessage}");
    	}
}

Key Features:

  • EncryptManager(int keyLength): Initializes the key generator with the specified key length (e.g., 1024 as Array Length ).
  • GetPublicKey(): Retrieves the public key that can be shared with the communication partner.
  • InitSharedKey(string partnerPublicKey): Initializes the shared key using the partner's public key.
  • EncryptMessage(string message): Encrypts a message using the shared key.
  • DecryptMessage(string message): Decrypts a received message using the shared key.

Key Exchange and Message Encryption Example

Two parties (e.g., user1 and user2) generate their own private and public keys. The public keys are exchanged between the two parties. Each party initializes the shared key using the public key of the other party. Now both parties can securely encrypt and decrypt messages using the shared key.

Requirements:

.NET 8.0

License

This project is licensed under the MIT License. See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET 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.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.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
1.0.1 176 9/17/2024