generateKey static method

Future<HmacSecretKey> generateKey(
  1. Hash hash, {
  2. int? length,
})

Generate random HmacSecretKey.

The length specifies the length of the secret key in bits. If omitted the random key will use the same number of bits as the underlying hash algorithm given in hash.

Example

import 'package:webcrypto/webcrypto.dart';

// Generate a new random HMAC secret key.
final key = await HmacSecretKey.generate(Hash.sha256);

Implementation

static Future<HmacSecretKey> generateKey(Hash hash, {int? length}) {
  if (length != null && length <= 0) {
    throw ArgumentError.value(length, 'length', 'must be positive');
  }

  return impl.hmacSecretKey_generateKey(hash, length: length);
}