Lpd 1.0.1
dotnet add package Lpd --version 1.0.1
NuGet\Install-Package Lpd -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="Lpd" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Lpd --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Lpd, 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.
// Install Lpd as a Cake Addin #addin nuget:?package=Lpd&version=1.0.1 // Install Lpd as a Cake Tool #tool nuget:?package=Lpd&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Table of Contents
Overview <a name='Overview'></a>
- You may use this class library for GDPR and/or PCI DSS requirements implementation in your apps
- This package provides a class library that implements basic Encrypt/Decrypt algoritms
- Library tested for .net462 and .core 8
GDPR requirements <a name='GDPR-requirements'></a>
highly short description (about data saving only)
- We should save sensitive data as encrypted (about repository implmentation, here)
- Sensitive data in Logs should be encrypted (about encrypted logger, here)
- All activities with sensitive data should be logged (about that every method in service should makes a record in an encrypted logger, here)
- You may find demo impmlementation of all items in the Lpd - examples and main parts are here in the end, here
Classes <a name='Classes'></a>
using Lpd.Classes;
KeyAndIV keyAndIV = KeyAndIV.Random();
//or get from storage
var Key_data = readKey_FromConfigOrDB();//should be implemented
var IV_data = readIV_FromConfigOrDB();//should be implemented
KeyAndIV keyAndIV_fromStorage = new KeyAndIV(Key_data, IV_data);
Console.WriteLine(keyAndIV);
Helpers <a name='Helpers'></a>
- StringsEncryptionHelper includes Encodings
- StreamsEncryptionHelper
- BytesEncryptionHelper
- ObjectsEncryption (you may skip properties via CiphIgnored attribute, and set Encoding via attribute Encoding)
- FilesEncryptionHelper supports CSV (Include Encoding), text (Include Encoding) and binary (not optimized for big files) files
- Limited version of DeepCopy is used, it should be enough for DAL/DTO objects
- Full solution with examples for every feature here
DeepCopy <a name='DeepCopy'></a>
Lpd - Limited version of DeepCopy
- It's enough for GDPR, PCI DSS data objects and so on, look at limitations below
- Code embedded in the package from this link https://www.codeproject.com/Articles/1111658/Fast-Deep-Copy-by-Expression-Trees-C-Sharp
The DeepCopy code limitations:
- Works for .NET 4 and higher(C# 4.0 and higher)
- Does not copy delegates and events(leaves null instead)
- Fails on ComObjects(e.g.on some WPF dispatcher subobjects or Excel Interop)
- Fails on any unmanaged object (e.g.from some external C++ library)
Examples <a name='Examples'></a>
- You may find examples about every EncryptionHelper
- 3-tier app for .net462, database LiteDB (NoSql)
- 3-tier app for .core 8, database SqLite (Sql), EF was used
- Feel free to find apps and/or ask the developer in telegram group https://t.me/+DAbYvN3C7Q9hZDAy (the best choice)
- Feel free to find apps on https://github.com/qart2003/Lpd
- Some examples use additional Lpd packages like Lpd.ObjectFaker and Lpd.ImageFaker.[Windows|Core] (it depends from platform)
- Main parts are below
Context example 'AppDbContext' (DAL assembly)
Repository example 'PersonRepository' (DAL assembly)
Encrypted Logger example 'EncryptedLogService '(SL assembly)
Service example 'PersonService' (SL assembly)
ManagerService is like a root point of App, just for example
DbContext
Full solution with examples for every feature here
//Context for EF
using Lpd.Classes;
using Microsoft.EntityFrameworkCore;
using NStdApp.DTO;
namespace Net8app.DAL
{
public class AppDbContext : DbContext
{
public DbSet<SimplePersonDTO> People { get; set; }
public DbSet<SimpleWorkerDTO> Workers { get; set; }
public string ConnectionString { get; private set; }
public KeyAndIV KeyAndIV { get; private set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite(ConnectionString);
}
public AppDbContext(string cstr, KeyAndIV keyAndIV)
{
ConnectionString = cstr;
KeyAndIV = keyAndIV;
}
}
}
Repository example <a name='repoFromDemo'></a>
Full solution with examples for every feature here
using Lpd.Classes;
using Lpd.Helpers.ForObjects.AsExt;
using NStdApp.DTO;
namespace Net8app.DAL
{
public class PersonRepository
{
private readonly AppDbContext _context;
private KeyAndIV keyAndIV => _context.KeyAndIV;
public PersonRepository(AppDbContext context)
{
_context = context;
}
public SimplePersonDTO? Find(string id)
{
return _context.People.FirstOrDefault(x => x.Id == id);
}
public void Add(SimplePersonDTO person)
{
_context.People.Add(person.Encrypt(keyAndIV));
_context.SaveChanges();
}
public List<SimplePersonDTO> FindAll()
{
return _context.People
.Select(v => v.Decrypt(keyAndIV))
.ToList();
}
public void Update(SimplePersonDTO person)
{
_context.People.Update(person.Encrypt(keyAndIV));
_context.SaveChanges();
}
public void Delete(string id)
{
var person = Find(id);
if (person != null)
{
_context.People.Remove(person);
_context.SaveChanges();
}
}
}
}
Encrypted Logger example <a name='loggerFromDemo'></a>
Full solution with examples for every feature here
using Lpd.Classes;
using Lpd.Helpers;
using Serilog;
namespace Net8app.SL
{
public class EncryptedLogService : BaseService
{
public KeyAndIV KeyAndIV => ManagerService.KeyAndIV;
public string Delimiter { get; private set; } = ">>>> ";
private Serilog.Core.Logger Logger { get; set; }
public string WorkerAsString()
{
try
{
var user = ManagerService.GetCurrentWorker();
return user.AsTextForLog;
}
catch
{
return string.Empty;
}
}
public string PersonAsString()
{
try
{
var person = ManagerService.GetCurrentPerson();
return person.AsTextForLog;
}
catch
{
return string.Empty;
}
}
private string MakeLogString(string s)
{
string worker = WorkerAsString();
string person = PersonAsString();
string result = worker.Length > 0 ? "Worker is " + worker : string.Empty;
result += person.Length > 0 ? "Person is " + person : string.Empty;
return result + " data: " + s;
}
public void Information(string s)
=> Logger.Information($"{Delimiter}{StringsEncryptionHelper.Encrypt(MakeLogString(s), KeyAndIV)}");
public void Warning(string s)
=> Logger.Warning($"{Delimiter}{StringsEncryptionHelper.Encrypt(MakeLogString(s), KeyAndIV)}");
public void Debug(string s)
=> Logger.Debug($"{Delimiter}{StringsEncryptionHelper.Encrypt(MakeLogString(s), KeyAndIV)}");
public void Fatal(string s)
=> Logger.Fatal($"{Delimiter}{StringsEncryptionHelper.Encrypt(MakeLogString(s), KeyAndIV)}");
public void Error(string s)
=> Logger.Error($"{Delimiter}{StringsEncryptionHelper.Encrypt(MakeLogString(s), KeyAndIV)}");
public EncryptedLogService(ManagerService managerService) : base(managerService)
{
Logger = new LoggerConfiguration()
.WriteTo.File(System.IO.Path.Combine(ManagerService.Dir, @"cryptedlogs/log.txt"),
rollingInterval: RollingInterval.Day,
rollOnFileSizeLimit: true)
.CreateLogger();
Information("Logger was created in the SL.EncryptedLogService");
}
}
}
PersonService example <a name='serviceFromDemo'></a>
Full solution with examples for every feature here
using Net8app.SL.Exts;
using NStdApp.BLL;
using NStdApp.DTO;
namespace Net8app.SL
{
public class PersonService : BaseService
{
public PersonService(ManagerService managerService):base(managerService) { }
public SimplePerson? Find(string guid)
{
this.ManagerService.EncryptedLogService.Information($"Start Find Person by guid={guid}");
var person = this.PersonRepository.Find(guid);
this.ManagerService.EncryptedLogService.Information($"Find Person with guid={guid} was finished");
return person?.Convert();
}
public List<SimplePerson> FindAll()
{
this.ManagerService.EncryptedLogService.Information("Start Find All SimplePersons");
var persons = this.PersonRepository.FindAll();
this.ManagerService.EncryptedLogService.Information("Find All SimplePersons was finished");
return persons
.Select(person => person.Convert())
.ToList();
}
public void Add(SimplePerson person)
{
this.ManagerService.EncryptedLogService.Information("Start Add Person");
this.PersonRepository.Add(SimplePersonDTO.Convert(person));
this.ManagerService.EncryptedLogService.Information("Add Person was finished");
}
public void Del(string guid)
{
this.ManagerService.EncryptedLogService.Information("Start Del Person");
this.PersonRepository.Delete(guid);
this.ManagerService.EncryptedLogService.Information("Del Person was finished");
}
public void Update(SimplePerson person)
{
this.ManagerService.EncryptedLogService.Information("Start Update Person");
this.PersonRepository.Add(SimplePersonDTO.Convert(person));
this.ManagerService.EncryptedLogService.Information("Update Person was finished");
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CSharp (>= 4.7.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Lpd:
Package | Downloads |
---|---|
Lpd.Exts.ObjectBinarization
Additional for Lpd is for saving cached or logging complex objects |
GitHub repositories
This package is not used by any popular GitHub repositories.