Skip to content

smarthead/EntityFramework.DataProtection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Actions Status Nuget Nuget Quality Gate Status Coverage Lines of Code

EF.DataEncryption

  • Flexible
  • Declarative
  • Linq support (with limitations)
  • Supports netstandard 2.1

Status

This library is still under construction and needs to be peer reviewed as well as have features added. Feel free to contribute project.

Usage

Add reference to EF.DataProtection.Services to your project.

dotnet add package EF.DataProtection.Services

Include the following code to Startup.cs

  services
      .AddEntityFrameworkSqlite()
      .AddDbContext<SampleDbContext>(
          (p, opt) =>
          {
              opt.UseSqlite(_connection)
                  .UseInternalServiceProvider(p);
          })
      .AddEfEncryption()
      .AddAes256(opt =>
      {
          opt.Password = "Really_Strong_Password_For_Data";
          opt.Salt = "Salt";
      })
      .AddSha512(opt => { opt.Password = "Really_Strong_Password_For_Data"; });

Add reference to EF.DataProtection.Abstractions to your domain model project.

dotnet add package EF.DataProtection.Abstractions

Mark properties in your entity with attributes Aes256 or Sha512

  public class PersonalData
  {
      [Aes256]
      public string PhoneNumber { get; set; }

      [Aes256]
      public string Email { get; set; }

      [Aes256]
      public string SensitiveData { get; set; }

      [Sha512]
      public string PhoneNumberHash { get; protected set; }
  }

Enjoy! You can find the full example here

Limitations

  • Only string supported
  • Sha512 doesn`t return value after hashing
  • There is no way to search by encrypted value. Use hash for search.

Maintainers