SubtleBlazor 0.2.0
dotnet add package SubtleBlazor --version 0.2.0
NuGet\Install-Package SubtleBlazor -Version 0.2.0
<PackageReference Include="SubtleBlazor" Version="0.2.0" />
<PackageVersion Include="SubtleBlazor" Version="0.2.0" />
<PackageReference Include="SubtleBlazor" />
paket add SubtleBlazor --version 0.2.0
#r "nuget: SubtleBlazor, 0.2.0"
#:package SubtleBlazor@0.2.0
#addin nuget:?package=SubtleBlazor&version=0.2.0
#tool nuget:?package=SubtleBlazor&version=0.2.0
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
Install the SubtleBlazor nuget package
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();
}
- 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 | Versions 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. |
-
net6.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.FileProviders.Embedded (>= 6.0.21)
- Microsoft.JSInterop (>= 6.0.21)
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 |