exportPkcs8Key method

Future<Uint8List> exportPkcs8Key()

Export the EcdhPrivateKey as a PKCS #8 key.

Returns the DER encoding of the PrivateKeyInfo structure specified in RFC 5208 as a list of bytes.

Example

import 'package:pem/pem.dart';
import 'package:webcrypto/webcrypto.dart';

Future<void> main() async {
  // Generate a key-pair
  final kp = await EcdhPrivateKey.generateKey(EllipticCurve.p256);

  // Export the private key.
  final exportedPkcs8Key = await kp.privateKey.exportPkcs8Key();

  // Private keys are often encoded as PEM.
  // This encodes the key in base64 and wraps it with:
  // '-----BEGIN PRIVATE KEY----'...
  print(PemCodec(PemLabel.privateKey).encode(exportedPkcs8Key));
}

Implementation

Future<Uint8List> exportPkcs8Key() => _impl.exportPkcs8Key();