SpawnDev.BlazorJS.Cryptography 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package SpawnDev.BlazorJS.Cryptography --version 1.0.0
                    
NuGet\Install-Package SpawnDev.BlazorJS.Cryptography -Version 1.0.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="SpawnDev.BlazorJS.Cryptography" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SpawnDev.BlazorJS.Cryptography" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="SpawnDev.BlazorJS.Cryptography" />
                    
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 SpawnDev.BlazorJS.Cryptography --version 1.0.0
                    
#r "nuget: SpawnDev.BlazorJS.Cryptography, 1.0.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 SpawnDev.BlazorJS.Cryptography@1.0.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=SpawnDev.BlazorJS.Cryptography&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=SpawnDev.BlazorJS.Cryptography&version=1.0.0
                    
Install as a Cake Tool

SpawnDev.BlazorJS.Cryptography

NuGet version

A cross platform cryptography library that supports encryption with AES-GCM, shared secret generation with ECDH, data signatures with ECDSA, and hashing with SHA on Windows, Linux, and Browser (Blazor WebAssembly) platforms.

This project aims to simplify common cryptography tasks with an API that is consistent on .Net Web API servers and in the web browser with Blazor WebAssembly.

PortableCrypto and the related classes wrap underlying cryptographic classes that are chosen based on the current platform. On Window and Linux, classes such as AesGcm, ECDiffieHellman, ECDsa, and SHA from Microsoft's System.Security.Cryptography library are used. When running under Blazor WebAssembly on the browser the browser Crypto and SubtleCrypto APIs are used. By wrapping these underlying libraries we can provide a consistent and reliable API regardless of the executing platform.

Getting started

Add the Nuget package

dotnet add package SpawnDev.BlazorJS.Cryptography

Add PortableCrypto service and SpawnDev.BlazorJS dependency to Program.cs


// Add BlazorJSRuntime service
builder.Services.AddBlazorJSRuntime();

// Add PortableCrypto service
builder.Services.AddSingleton<PortableCrypto>();

Inject PortableCrypto

[Inject] PortableCrypto PortableCrypto { get; set; }

PortableCrypto

  • The PortableCrypto service provides an API that can be used on the server and on the browser to provide cross platform compatible cryptographic methods.

PortableCrypto - SHA

Task<byte[]> Digest(string hashName, byte[] data)
  • Hash the specified data using the specified hash algorithm

PortableCrypto - ECDH

Task<PortableECDHKey> GenerateECDHKey(string namedCurve = NamedCurve.P521, bool extractable = true)
  • Generate a new ECDH crypto key
Task<byte[]> ExportPublicKeySpki(PortableECDHKey key)
  • Export the ECDH public key in Spki format
Task<byte[]> ExportPrivateKeyPkcs8(PortableECDHKey key)
  • Export the ECDH private key in Pkcs8 format
Task<PortableECDHKey> ImportECDHKey(byte[] publicKeySpki, string namedCurve = NamedCurve.P521, bool extractable = true)
  • Import the ECDH public key
Task<PortableECDHKey> ImportECDHKey(byte[] publicKeySpki, byte[] privateKeyPkcs8, string namedCurve = NamedCurve.P521, bool extractable = true)
  • Import the ECDH private key
Task<byte[]> DeriveBits(PortableECDHKey localPartyKey, PortableECDHKey otherPartyKey, int bitLength)
  • Create a shared secret that is cross-platform compatible
Task<byte[]> DeriveBits(PortableECDHKey localPartyKey, PortableECDHKey otherPartyKey)
  • Create a shared secret that is cross-platform compatible

PortableCrypto - ECDSA

Task<PortableECDSAKey> GenerateECDSAKey(string namedCurve = NamedCurve.P521, bool extractable = true)
  • Generate a new ECDSA key
Task<byte[]> ExportPublicKeySpki(PortableECDSAKey key)
  • Exports the ECDSA public key in Spki format
Task<byte[]> ExportPrivateKeyPkcs8(PortableECDSAKey key)
  • Exports the ECDSA private key in Pkcs8 format
Task<PortableECDSAKey> ImportECDSAKey(byte[] publicKeySpkiData, string namedCurve = NamedCurve.P521, bool extractable = true)
  • Import an ECDSA public key
Task<PortableECDSAKey> ImportECDSAKey(byte[] publicKeySpkiData, byte[] privateKeyPkcs8Data, string namedCurve = NamedCurve.P521, bool extractable = true)
  • Import an ECDSA public and private key
Task<bool> Verify(PortableECDSAKey key, byte[] data, byte[] signature, string hashName = HashName.SHA512)
  • Verify a data signature
Task<byte[]> Sign(PortableECDSAKey key, byte[] data, string hashName = HashName.SHA512)
  • Sign data using an ECDSA key
Product Compatible and additional computed target framework versions.
.NET 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.  net9.0 is compatible.  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 (3)

Showing the top 3 NuGet packages that depend on SpawnDev.BlazorJS.Cryptography:

Package Downloads
SpawnDev.WebTorrent

Pure C# BitTorrent/WebTorrent client. 18 BEPs including BEP 52 v2 (SHA-256 + Merkle + hybrid + pure-v2 end-to-end), real WebRTC P2P (browser + desktop via SpawnDev.RTC), DHT with mutable items (BEP 46 — AI agent communication), web seeds, media streaming with seeking via service worker, OPFS storage. Includes webtorrent-sw.js for COI headers + torrent streaming. No JavaScript dependencies. Runs on desktop (.NET + SIPSorcery) and browser (Blazor WASM + SpawnDev.BlazorJS). 468+ shared test methods running on both browser and desktop runtimes + libtorrent 2.0 external-interop fixtures.

SpawnDev.Identification

Identity verification using ECDSA signatures for browser and non-browser platforms.

SpawnDev.RTC

Cross-platform WebRTC for .NET. Browser (Blazor WASM) and desktop from a single API. Data channels, audio, video, media streams, tracks, transceivers, ICE, DTLS, SCTP. Zero-copy JS types in WASM. Serverless signaling via WebTorrent tracker protocol. Powered by SpawnDev.BlazorJS (browser) and SipSorcery (desktop).

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.2.0 622 4/15/2026
3.1.0 133 4/4/2026
3.0.1 294 3/18/2026
3.0.0 785 2/12/2026
2.7.0 119 2/11/2026
2.6.0 173 1/22/2026
2.5.0 133 1/10/2026
2.4.0 489 11/19/2025
2.3.0 1,937 11/10/2025
2.2.0 226 10/1/2025
2.1.0 1,782 5/5/2025
2.0.10 224 1/3/2025
2.0.9 197 1/1/2025
2.0.8 207 12/30/2024
2.0.7 195 12/18/2024
2.0.6 191 12/5/2024
2.0.5 198 11/22/2024
2.0.3 185 11/16/2024
2.0.2 203 11/15/2024
1.0.0 196 11/12/2024
Loading failed