toDer method

Uint8List toDer()

Constructs DER encoding of this public key.

The implementation generates DER encodings identical to those generated by Apple CryptoKit.

Implementation

Uint8List toDer() {
  final config = CupertinoEcDer.get(type);
  final numberLength = config.numberLength;
  final d = _ensureNumberLength(this.d, numberLength, 'd');
  final x = _ensureNumberLength(this.x, numberLength, 'x');
  final y = _ensureNumberLength(this.y, numberLength, 'y');
  return Uint8List.fromList([
    ...config.privateKeyPrefix,
    ...d,
    ...config.privateKeyMiddle,
    ...x,
    ...y,
  ]);
}