Skip to content

Add PKCS extensionsfor for Blazor WebAssembly and light WebCrypto interop.

License

Notifications You must be signed in to change notification settings

harrison314/PkcsExtensions.Blazor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PkcsExtensions.Blazor

NuGet Status

Add crypto and digital signature functionality for Blazor and light WebCrypto interop.

Features

  • Namespace PkcsExtensions.Blazor:
    • IWebCryptoProvider - provide generate random numbers, generate RSA and ECDSA (as JsonWebKey) key pairs
    • IEcWebCryptoProvider - provide methods GetSharedDhmSecret for derive bytes using Diffie Hellman Merkle and GetSharedEphemeralDhmSecret for ECIES scheme.
  • Namespace PkcsExtensions.Blazor.Jwk - implementation of JsonWebKey
  • Namespace PkcsExtensions.Blazor.Security - extensions for System.Security.Cryptography

Usage

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();
        }
    }

Examples

See other examples.

Recommendations

  • 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.

Read more

  1. PkcsExtensions
  2. WebCrypto support in browsers

About

Add PKCS extensionsfor for Blazor WebAssembly and light WebCrypto interop.

Resources

License

Stars

Watchers

Forks

Packages

No packages published