Project Description


Copy Rights

This is a cloned .Net Core version of orginal work from https://github.com/sjh37/Effortless-.Net-Encryption

Special thanks to Simon Hughes https://github.com/sjh37


**Before You Begin**

1. Supported .Net Core Versions : 5.0

2. Supported Operating System : Windows

3. According to .Net Core source code, only 128 Block Size is supported in Rijndael, Sources:


Installation

https://www.nuget.org/packages/Effortless.Net.Core.Encryption/

To install Effortless.Net.Core.Encryption, run the following command in the Package Manager Console

PM> dotnet add package Effortless.Net.Core.Encryption

Overview

The project is split into four main areas

    • Strings – Encryption/Decryption/Password and Salt generation
    • Hash – Creation and verification of hashes using MD5, SHA1, SHA256, SHA384, SHA512.
    • Digest – Creation and verification of digests (data + hash). Plus two handy ToString() and CreateFromString() functions which come in handy if you want to store data in a Cookie.
    • Bytes – The core of the library. This uses the Rijndael algorithm and works at the byte[] level for most functions.

Examples


    // Creating passwords & salts
    string password = Strings.CreatePassword(15, true);
    string salt = Strings.CreateSalt(20);

    // Encrypting/decrypting strings
    byte[] key = Bytes.GenerateKey();
    byte[] iv = Bytes.GenerateIV();
    string encrypted = Strings.Encrypt("Secret", key, iv);
    string decrypted = Strings.Decrypt(encrypted, key, iv);
    Assert.AreEqual("Secret", decrypted);

    // Hashes
    string hash = Hash.Create(HashType.SHA512, "Hello", string.Empty, false);

    // Digests
    var d1 = Digest.Create(HashType.MD5, "Hello", string.Empty);
    string cookieString = d1.ToString();
    var d2 = Digest.CreateFromString(cookieString, string.Empty);
    Assert.AreEqual(d1.Data, d2.Data);
    Assert.AreEqual(d1.Hash, d2.Hash);

    // Bytes
    byte[] key = Bytes.GenerateKey();
    byte[] iv = Bytes.GenerateIV();
    var data = new byte[1024];
    new RNGCryptoServiceProvider().GetBytes(data); // Random data
    byte[] encrypted = Bytes.Encrypt(data, key, iv);
    byte[] decrypted = Bytes.Decrypt(encrypted, key, iv);
    Assert.AreEqual(data, decrypted);

    // Digital Signatures
    var hash = Hash.Create(HashType.SHA256, "Hello", string.Empty)
    var ds = new DigitalSignature();
    ds.AssignNewKey();
    var signature = ds.SignData(hash);
    var result = ds.VerifySignature(hash, signature);
    Assert.IsTrue(result);

    // Diffie Hellman
    var alice = new DiffieHellman();
    var bob = new DiffieHellman();
    // Bob uses Alice's public key to encrypt his message.
    var secretMessage = bob.Encrypt(alice, "Hello");
    // Alice uses Bob's public key and IV to decrypt the secret message.
    var decryptedMessage = alice.Decrypt(bob, secretMessage);
    Assert.AreEqual("Hello", decryptedMessage);

Code Coverage


    +---------------------------+--------+--------+--------+
    | Module                    | Line   | Branch | Method |
    +---------------------------+--------+--------+--------+
    | Effortless.Net.Encryption | 86.42% | 54.13% | 86.11% |
    +---------------------------+--------+--------+--------+

    +---------+--------+--------+--------+
    |         | Line   | Branch | Method |
    +---------+--------+--------+--------+
    | Total   | 86.42% | 54.13% | 86.11% |
    +---------+--------+--------+--------+
    | Average | 86.42% | 54.13% | 86.11% |
    +---------+--------+--------+--------+