7.3 Reading
A reader MUST treat a key file that fails any of these checks as malformed:
- It is at least 14 bytes long, and its first 8 bytes are
PEIOSKEY. versionis1.algorithmis a value §7.2 defines.protectionis1or2.- No bit of
flagsother than bit 0 is set, and bit 0 is clear ifprotectionis1. public_lenis not zero, and at least one byte followspublic_key.public_keyis the canonical DER encoding of a key ofalgorithm.
A reader can describe a key from these fields alone: its algorithm, its public key, how it is protected, and whether it may be exported.
To open the private key, a reader takes private_key as it is, with
access-control protection, or opens it as a sealed secret under the
key's passphrase (§6.3), with passphrase protection. It then parses the
PKCS #8 encoding, and MUST refuse the key unless it is a key of
algorithm whose public key is exactly public_key.
A program that holds a key file whose not-exportable flag is set MUST NOT release the private key, sealed or in the clear.