newKeyPairFromSeed method

  1. @override
Future<SimpleKeyPair> newKeyPairFromSeed(
  1. List<int> seed
)
override

Generates a key pair from the seed.

This will throw UnsupportedError if the algorithm does not support seeds for private key generation.

Example

In this example, we use X25519:

import 'dart:convert';
import 'package:cryptography/cryptography.dart';

Future<void> main() async {
  // X25519 seed is any 32 bytes.
  // We can use SHA256, which computes a 32-byte hash from any input.
  final seed = utf8.encode('example');
  final seedWith32Bytes = (await Sha256().hash(seed)).bytes;

  final algorithm = X25519();
  final keyPair = await algorithm.newKeyPairFromSeed(seedWith32Bytes);
}

Implementation

@override
Future<SimpleKeyPair> newKeyPairFromSeed(List<int> seed) async {
  final modifiedBytes = DartX25519.modifiedPrivateKeyBytes(seed);
  return SimpleKeyPairData(
    modifiedBytes,
    publicKey: DartX25519._publicKey(modifiedBytes),
    type: KeyPairType.x25519,
  );
}