Add crypto and digital signature functionality for Blazor and light WebCrypto interop.
- Namespace PkcsExtensions.Blazor:
IWebCryptoProvider
- provide generate random numbers, generate RSA and ECDSA (as JsonWebKey) key pairsIEcWebCryptoProvider
- provide methodsGetSharedDhmSecret
for derive bytes using Diffie Hellman Merkle andGetSharedEphemeralDhmSecret
for ECIES scheme.
- Namespace PkcsExtensions.Blazor.Jwk - implementation of JsonWebKey
- Namespace PkcsExtensions.Blazor.Security - extensions for System.Security.Cryptography
Install package dotnet add package PkcsExtensions.Blazor
to Blazor WebAssebmly project.
Add to index.html:
<script src="_content/PkcsExtensions.Blazor/WebCryptoInterop.js"></script>
or minifiy version:
<script src="_content/PkcsExtensions.Blazor/WebCryptoInterop.min.js"></script>
And register services in Main method:
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.Services.AddSingleton(new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Services.AddWebCryptoProvider();
WebAssemblyHost host = builder.Build();
await host.RunAsync();
}
}
See other examples.
- Avoid use WebCyrpto for hashing, HMAC-ing, encryption, because their implementations has differs between browsers and operating systems. Use .Net implementation.
- Avoid use WebCrypto for digital signing because it does not support hash signing.
- Hint: Consider using high performance elliptic curves Curve25519, Ed25519 or similar. Use full managed implementation e.g. Chaos.NaCl library.