module

Beryl::Certificates::PrivateKeyFile

Reads private keys from the files TLS servers are configured with: PKCS #8 (PRIVATE KEY, RFC 5958), SEC 1 (EC PRIVATE KEY, RFC 5915) and PKCS #1 (RSA PRIVATE KEY, RFC 8017 Appendix A.1.2), in PEM or DER.

key = Beryl::Certificates::PrivateKeyFile.read_pem(File.read("server.key"))

Keys: RSA with two primes, 2,048 to 4,096 bits; P-256; Ed25519. Encrypted PKCS #8 files are not read. The DER Beryl decodes from PEM is wiped once the key is built; the caller owns, and should wipe, the text or bytes it hands in. The lengths in a key's DER are public (they are in the file's size), so reading them is not a secret-dependent branch beyond what the file already shows.

Class methods

read_der(bytes : Bytes) : SigningKey

Reads a DER PKCS #8 PrivateKeyInfo (RFC 5958 OneAsymmetricKey).

Source
read_elliptic_curve_der(bytes : Bytes, curve : DER::ObjectIdentifier | Nil = nil) : SigningKey

Reads a DER ECPrivateKey (RFC 5915). curve is the curve the enclosing PKCS #8 names; a SEC 1 file names it itself.

Source
read_pem(text : String) : SigningKey

Reads the first private key block in the PEM text.

Source
read_rsa_der(bytes : Bytes) : SigningKey

Reads a DER RSAPrivateKey (RFC 8017 Appendix A.1.2), two primes only.

Source

Nested types