decodePkcs8

Reads a P-256 key from PKCS #8 DER (PrivateKeyInfo, RFC 5958), as encodePkcs8 or OpenSSL writes it. Throws IllegalArgumentException when the bytes are not such a key, including when the public key it carries does not belong to its private key.

That last check is not paranoia: the JDK provider takes the embedded public key on trust, so without it a file whose public key was swapped would decode, and boxes sealed to the swapped key would never open. Here the private half signs a fixed message and the public half must verify it, on every platform. A signature, not a key agreement: ECDH yields only the x-coordinate, which a point and its negation share, so an agreement check accepts a file whose public key was replaced by its negation. A DER without the optional public key is refused on JVM and Android, where the provider cannot recompute it; other platforms may accept one.