1

We are trying to integrate Subtlecrypto into our blazor webassembly app. It seems this is the only cryptography package that blazor wasm supports.

According to the official example, there is not a way to change/custom the secret key. If the secret is assigned at startup, the key is fixed and used across the application:

using Blazor.SubtleCrypto;

builder.Services.AddSubtleCrypto(opt => 
    opt.Key = "ELE9xOyAyJHCsIPLMbbZHQ7pVy7WUlvZ60y5WkKDGMSw5xh5IM54kUPlycKmHF9VGtYUilglL8iePLwr" 
    );

Or one can use random key and iv that the application has no control.

In our app we hope to ask the user to enter a key, which is used to encrypt some data. A fixed key can work but it seems less secure.

Is there a way to achieve a custom secret key?

Cal
  • 747
  • 1
  • 13
  • 30

1 Answers1

1

Below is what I did:

    var options = new CryptoOptions() { Key = "some_secret"};
    var crypto = new CryptoService(jsRuntime, options);
    string s = "abc";
    CryptoResult encrypted = await crypto.EncryptAsync(s);

    Console.WriteLine("Encrypted: " + encrypted.Value);

    string d = await crypto.DecryptAsync(encrypted.Value);

    Console.WriteLine("Decrypted: " + d);
Cal
  • 747
  • 1
  • 13
  • 30