signStream abstract method

Future<Uint8List> signStream(
  1. Stream<List<int>> data
)

Compute an HMAC signature of given data stream.

This computes an HMAC signature of the data stream using hash algorithm and secret key material held by this HmacSecretKey.

Example

import 'dart:convert' show base64, utf8;
import 'package:webcrypto/webcrypto.dart';

// Generate an HmacSecretKey.
final key = await HmacSecretKey.generateKey(Hash.sha256);

String stringToSign = 'example-string-to-signed';

// Compute signature.
final signature = await key.signStream(Stream.fromIterable([
  utf8.encode(stringToSign),
]));

// Print as base64
print(base64.encode(signature));

This method should not be used for validating other signatures by generating a new signature and then comparing the two signatures. While this technically works, your application might be vulnerable to timing attacks. To validate signatures use verifyBytes or verifyStream instead, these methods computes a signature and does a fixed-time comparison.

Implementation

Future<Uint8List> signStream(Stream<List<int>> data);