encodeEd25519PrivateKeyPkcs8 static method

SecretBytes encodeEd25519PrivateKeyPkcs8(
  1. List<int> seed
)

PKCS8 PrivateKeyInfo for Ed25519. The "privateKey" OCTET STRING contains the DER of a further OCTET STRING wrapping the raw 32-byte seed (RFC 8410's "CurvePrivateKey").

Implementation

static SecretBytes encodeEd25519PrivateKeyPkcs8(List<int> seed) {
  if (seed.length != 32) {
    throw CoreErrors.cryptoFailed(
      "encodeEd25519PrivateKeyPkcs8",
      reason: 'Ed25519 private key (seed) must be 32 bytes',
    );
  }
  final algId = DerUtils.derSequence([...DerUtils.derOid(Oids.ed25519)]);
  final curvePrivateKey = DerUtils.derOctetString(seed);
  return SecretBytes.take(
    DerUtils.derSequence([
      ...DerUtils.derSmallInt(0),
      ...algId,
      ...DerUtils.derOctetString(curvePrivateKey),
    ]),
  );
}