SubtleBlazor 0.2.0

dotnet add package SubtleBlazor --version 0.2.0
                    
NuGet\Install-Package SubtleBlazor -Version 0.2.0
                    
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="SubtleBlazor" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SubtleBlazor" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="SubtleBlazor" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SubtleBlazor --version 0.2.0
                    
#r "nuget: SubtleBlazor, 0.2.0"
                    
#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.
#:package SubtleBlazor@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SubtleBlazor&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=SubtleBlazor&version=0.2.0
                    
Install as a Cake Tool

SubtleBlazor

Disclaimer

SubtleBlazor is in development. The API may change without warning and I may find security issues that necessitate changes. Use at your own risk.

What is SubtleBlazor?

SubtleBlazor is a Blazor wrapper around a subset of the features of the Subtle Crypto javascript API.

It currently supports a limited number of scenarios:

  • Blazor WebAssembly in .Net 6+
  • Key derivation: PBKDF2 with SHA-256
  • Encryption: AES-GCM mode
  • Decryption: AES-GCM mode

If you'd like additional scenarios supported, feel free to submit a PR.

Setup

  1. Install the SubtleBlazor nuget package

  2. Modify your startup file to include the following

    public static async Task Main(string[] args)
    {
        var builder = WebAssemblyHostBuilder.CreateDefault(args);
        ...
        builder.Services.AddSubtleBlazor();
        ...
        await builder.Build().RunAsync();
    }
  1. Inject SubtleBlazorService into your pages
    [Inject]
    public SubtleBlazorService _crypto { get; set; }

See the SubtleBlazor.ExampleApp project for more.

Usage

Derive a key

    JWK result = await _crypto.DeriveKeyAsync(_pass, "1234567890");
    string jwk = JsonSerializer.Serialize(result);

Derive a key from the given derivation material (a password, whatever) and some salt.

Returns a JWK object, which is a .Net wrapper around a limited feature set of the JWK standard.

Encrypt

    EncryptionResult result = await _crypto.EncryptAsync(jwk, _plaintext);
    _ciphertext = JsonSerializer.Serialize(result);

Accepts a JWK object and the string plaintext. Returns an EncryptionResult, which includes the ciphertext and randomly-generated IV.

Decrypt

    EncryptionResult ciphertext = JsonSerializer.Deserialize<EncryptionResult>(_ciphertext);
    DecryptionResult decryptionResult = await _crypto.DecryptAsync(jwk, ciphertext.IV, ciphertext.CipherText);

Accepts a JWK object, an IV, and ciphertext. Returns a DecryptionResult, which includes the resulting plaintext.

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 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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
0.2.0 284 9/26/2023
0.2.0-alpha 202 9/26/2023
0.1.0 242 8/26/2023