encodeSecp256r1PrivateKeyPkcs8 static method

SecretBytes encodeSecp256r1PrivateKeyPkcs8(
  1. List<int> privateKey, {
  2. List<int>? publicKeyPoint,
})

Wraps a secp256r1 private key in a PKCS8 "PrivateKeyInfo". The curve OID lives in the AlgorithmIdentifier; the nested SEC1 structure omits it (matching common OpenSSL / RFC 5915 output).

Implementation

static SecretBytes encodeSecp256r1PrivateKeyPkcs8(
  List<int> privateKey, {
  List<int>? publicKeyPoint,
}) {
  final algId = DerUtils.derSequence([
    ...DerUtils.derOid(Oids.ecPublicKey),
    ...DerUtils.derOid(Oids.secp256r1),
  ]);
  final sec1 = encodeSecp256r1PrivateKeySec1(
    privateKey,
    publicKeyPoint: publicKeyPoint,
    includeCurveOid: false,
  );
  return SecretBytes.take(
    DerUtils.derSequence([
      ...DerUtils.derSmallInt(0),
      ...algId,
      ...DerUtils.derOctetString(sec1),
    ]),
  );
}