Skip to content

SecureLocalStorage for .NET: A simple and lightweight extension that allows you to safely store data locally.

Notifications You must be signed in to change notification settings

bytehide/SecureLocalStorage

Repository files navigation

Secure Local Storage

alt text

Secure Local Storage is a simple package for .NET that allows you to safely store information locally, allowing you to select whether the information will only be decryptable on the computer where it was created, or if it can be shared between several computers.

Mainly it offers you the option of storing information or sensitive settings and obtaining it from the same or another application.

Installation

Use the nuget package manager to install SecureLocalStorage.

Package Manager:

Install-Package SecureLocalStorage -Version 2.0.0

.NET CLI:

dotnet add package SecureLocalStorage --version 2.0.0

Caveat:

Version 1 does not support MacOs and Linux, so please upgrade to version 2 if you are encrypting local data in a cross-platform project.

Since version 2, both Mac and Linux and Windows have the ability to store fully encrypted local files and data on the machine where your software runs.

Simple Usage

Instantiate the class with the default settings:

var config = new DefaultLocalStorageConfig();
var storage = new SecureLocalStorage.SecureLocalStorage(config);

Add data to storage:

storage.Set("Example", "Hello world.");
//If key exists content will replaced.

Add custom data to storage:

var userExample = new UserExample {Name = "Juan", Verified = true};
storage.Set("User", userExample);

Get data from storage:

string data = storage.Get("Example"); //Hello world

Get custom data from storage:

var data = storage.Get<UserExample>("User"); //{Name = "Juan", Verified = true}

Remove data from storage:

storage.Remove("User");

Check if data exists on storage

var exists = storage.Exists("User");

Advanced Usage

By default, the information is encrypted with the values of the machine that runs the application and it is only possible to manipulate the data in the same environment, that is, information stored between devices cannot be stolen.

Optionally you can configure where that information is stored and how it is encrypted.

Custom configuration

The information is stored by default in Environment.SpecialFolder.ApplicationData.

and its hierarchy is as follows:

%SpecialFolder% / Your_App_Name / default.

Change default app name:

config = new CustomLocalStorageConfig(null, "DotnetsaferTesting").WithDefaultKeyBuilder();

Make sure the name is unique to your application, or it could create conflicts with other applications.

Change default path:

config = new CustomLocalStorageConfig(@"current/default", "DotnetsaferTesting").WithDefaultKeyBuilder();

Change default encryption key:

If you don't want the encryption key to be unique values of the device, you can set one yourself.

config = new CustomLocalStorageConfig(@"current/default", "DotnetsaferTesting", "secret1234");

If you want to add a dynamic key you can override the BuildLocalSecureKey method:

config.BuildLocalSecureKey = () => Guid.NewGuid().ToString();

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

About

SecureLocalStorage for .NET: A simple and lightweight extension that allows you to safely store data locally.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages