7.1 Binary Format

A key file holds one asymmetric key pair: the public key in the clear, so that a program can tell which key a file holds without opening it, and the private key, either sealed under a passphrase or kept in the clear for storage that access control protects. The certificate authority keeps every CA key in a key file, and exports keys only as sealed key files.

This chapter specifies version 1, identified by the magic PEIOSKEY.

Unlike most of this document, every multi-byte integer in a key file is big-endian.

7.1.1 Layout #

OffsetSizeFieldValue
08magicASCII PEIOSKEY
81version1
91algorithmThe key's algorithm, §7.2
101protection1, passphrase; 2, access control
111flagsBit 0, not exportable; the other bits zero
122public_lenLength of public_key, uint16
14public_lenpublic_keyThe public key, a DER SubjectPublicKeyInfo
14 + public_lenrestprivate_keyThe private key, as protection says

The first 14 bytes are the header. public_key and private_key are each at least one byte long, and private_key runs to the end of the file.

private_key depends on protection:

  • 1, passphrase: a sealed secret (§6) of the private key's PKCS #8 encoding, sealed under the key's passphrase.
  • 2, access control: the private key's PKCS #8 encoding itself. Only the access control of the storage that holds the file keeps it secret.

The not exportable flag asks the program that holds the key never to release it, even to a caller that may otherwise read it. It is meaningful only with access-control protection: whoever has a sealed key file and its passphrase already has the key.

The algorithm and protection enumerations and the flags bits are closed for version 1. A value this chapter doesn't define is not a version 1 key file.

Edit this page