Solutaris.InfoWARE.ProtectedBrowserStorage 1.0.2

dotnet add package Solutaris.InfoWARE.ProtectedBrowserStorage --version 1.0.2                
NuGet\Install-Package Solutaris.InfoWARE.ProtectedBrowserStorage -Version 1.0.2                
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="Solutaris.InfoWARE.ProtectedBrowserStorage" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Solutaris.InfoWARE.ProtectedBrowserStorage --version 1.0.2                
#r "nuget: Solutaris.InfoWARE.ProtectedBrowserStorage, 1.0.2"                
#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 Solutaris.InfoWARE.ProtectedBrowserStorage as a Cake Addin
#addin nuget:?package=Solutaris.InfoWARE.ProtectedBrowserStorage&version=1.0.2

// Install Solutaris.InfoWARE.ProtectedBrowserStorage as a Cake Tool
#tool nuget:?package=Solutaris.InfoWARE.ProtectedBrowserStorage&version=1.0.2                

Solutaris.InfoWARE.ProtectedBrowserStorage

Solutaris.InfoWARE.ProtectedBrowserStorage is a library that allows saving to browser's Local Storage and Session Storage in encrypted format for both Blazor WASM and Blazor Server Applications.

Yes! Protected Browser Storage now possible with Solutaris.InfoWARE.ProtectedBrowserStorage (it encrypts the data using AES encryption and then compresses it before saving to browser's local or session Storage).

With Solutaris.InfoWARE.ProtectedBrowserStorage you have a protected browser storage even in Blazor WASM - which is not possible with Microsoft's Protected Browser Storage (Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage namespace) as it relies on ASP .NET Core Data Protection (only supported for Blazor Server apps)!

Microsoft's Protected Browser Storage (Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage namespace) relies on ASP .NET Core Data Protection and is only supported for Blazor Server apps More Info.

With Solutaris.InfoWARE.ProtectedBrowserStorage you now have a protected browser storage in Blazor WASM!

Installing

To install the package add the following line to you csproj file replacing x.x.x with the appropriate version number:

<PackageReference Include="Solutaris.InfoWARE.ProtectedBrowserStorage" Version="x.x.x" />

You can also install via the .NET CLI with the following command:

dotnet add package Solutaris.InfoWARE.ProtectedBrowserStorage

If you're using Visual Studio you can also install via the built in NuGet package manager.

Add Reference to _host.cshtml or index.html file

Add this to your to index.html (For Blazor WASM), or _Layout.cshtml / _Host.cshtml (for Blazor Server)

<script src="_content/Solutaris.InfoWARE.ProtectedBrowserStorage/config.js"></script>

Setup in Program.cs (Blazor WASM)

using Solutaris.InfoWARE.ProtectedBrowserStorage.Extensions;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
.
.
.
builder.Services.AddIWProtectedBrowserStorageAsSingleton(); //optionally pass an encryption key (as string)

await builder.Build().RunAsync();

Setup in Program.cs (Blazor Server)

using Solutaris.InfoWARE.ProtectedBrowserStorage.Extensions;
var builder = WebApplication.CreateBuilder(args);
.
.
.
builder.Services.AddIWProtectedBrowserStorage(); //optionally pass an encryption key (as string)

await builder.Build().RunAsync();

Usage (Blazor WebAssembly)

To use Solutaris.InfoWARE.ProtectedBrowserStorage's LocalStorage in Blazor WebAssembly, inject the IIWLocalStorageService per the example below.

NOTE: For SessionStorage use Solutaris.InfoWARE.ProtectedBrowserStorage.Services.IIWSessionStorageService

@inject Solutaris.InfoWARE.ProtectedBrowserStorage.Services.IIWLocalStorageService localStorage

@code {

    protected override async Task OnInitializedAsync()
    {
        await localStorage.SetItem("name", "John Doe");
        var name = await localStorage.GetItem<string>("name");
    }

}

Usage (Blazor Server)

NOTE:

  • Due to pre-rendering in Blazor Server you can't perform any JS interop until the OnAfterRender lifecycle method.
  • For SessionStorage use: Solutaris.InfoWARE.ProtectedBrowserStorage.Services.IIWSessionStorageService
@inject Solutaris.InfoWARE.ProtectedBrowserStorage.Services.IIWLocalStorageService localStorage

@code {

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        await localStorage.SetItemAsync("name", "John Doe");
        var name = await localStorage.GetItemAsync<string>("name");
    }

}

The APIs available are:

  • SetItem()
  • GetItem()
  • RemoveItem()
  • RemoveAllItems()
  • SetItemAsync()
  • GetItemAsync()
  • RemoveItemAsync()
  • RemoveAllItemsAsync()

Note:

  • API Synchronous methods are strictly for Blazor WASM only, as JavaScript calls (Interoperablity) are directly available in WASM but not in Blazor Server.
  • API Asynchronous methods are supported by both Blazor Server and Blazor WASM, but not recommended for WASM - synchronous variant is best for WASM.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 1,233 8/18/2024
1.0.1 4,325 12/6/2023
1.0.0 13,374 6/8/2022

Added .Net 8.0 Support