Skip to main content

load_private_key

Function load_private_key 

Source
pub fn load_private_key(
    p: &Policy,
    der: PrivateKeyDer<'static>,
) -> Result<Arc<dyn SigningKey>, CryptoError>
Expand description

Loads a private key into a signing key that signs only with a scheme in p.signature_schemes. The key’s algorithm is not checked against any profile; Resolved::certified_key checks it.

A key is taken only when it is one of these, with nothing after it (decision 0015):

  • Pkcs8: an RFC 5958 PrivateKeyInfo in the structure signature::KeyPair::from_pkcs8_der takes, holding an ECDSA key on P-256, P-384 or P-521 (its scalar and point as for Sec1), an Ed25519 key, an RSA key as below, or, on the 4.x line, an ML-DSA-87 key;
  • Sec1: one RFC 5915 ECPrivateKey on P-256, P-384 or P-521, with its parameters, a scalar of the curve’s length and, if it carries a public key, an uncompressed point;
  • Pkcs1: one two-prime RFC 8017 RSAPrivateKey.

An RSA key is 2048, 3072 or 4096 bits with public exponent 65537. Anything else is refused with CryptoError::Tls(TlsError::PrivateKey).