Skip to content
This repository has been archived by the owner on May 20, 2022. It is now read-only.

Latest commit

 

History

History
67 lines (50 loc) · 1.7 KB

README.md

File metadata and controls

67 lines (50 loc) · 1.7 KB

⚠️ This repository is not maintained ⚠️


SmartContract.Essentials

Build Status Nuget

Overview

This is a set of tools that can be used to simplify the development of smart contract applications. Currently the tools included can be used for data encryption and string generation.

Usage

Setting up DI

Encryption providers can be created through a factory, allowing you to adhere to SOLID guidelines and test your implementation more easily. Begin by adding the factory to your container.

services.AddSingleton<ICipherFactory, AesCipherFactory>();

Encrypting personal data

var customerName = "Benjamin Swift";

CbcResult customerNameEncryptionResult;
try
{
    using var cbc = _cipherFactory.CreateCbcProvider();
    customerNameEncryptionResult = cbc.Encrypt(customerName);
}
catch (CryptographicException e)
{
}
catch (ArgumentException e)
{
}

// persist cipher to contract
// give user control of key and IV

Decrypting personal data

string customerName;
try
{
    using var cbc = _cipherFactory.CreateCbcProvider();
    customerName = cbc.Decrypt(customerNameCipher, key, iv);
}
catch (CryptographicException e)
{
}
catch (ArgumentException e)
{
}

Generating a random string

var generator = new UrlFriendlyStringGenerator();
var value = generator.CreateUniqueString(24);