Struct osshkeys::keys::KeyPair[][src]

pub struct KeyPair { /* fields omitted */ }
Expand description

General key pair type

This is a type to make it easy to store different types of key pair in the container. Each can contain one of the types supported in this crate.

Key pair is the so-called “private key” which contains both public and private parts of an asymmetry key.

Implementations

Parse a keypair from supporting file types

The passphrase is required if the keypair is encrypted.

OpenSSL PEM
  • Begin with -----BEGIN DSA PRIVATE KEY----- for dsa key.
  • Begin with -----BEGIN RSA PRIVATE KEY----- for rsa key.
  • Begin with -----BEGIN EC PRIVATE KEY----- for ecdsa key.
  • This file type doesn’t support Ed25519
PKCS#8 Format
  • Begin with -----BEGIN PRIVATE KEY-----
Openssh
  • Begin with -----BEGIN OPENSSH PRIVATE KEY-----

This is the new format which is supported since OpenSSH 6.5, and it became the default format in OpenSSH 7.8. The Ed25519 key can only be stored in this type.

Generate a key of the specified type and size

Key Size

There are some limitations to the key size:

  • RSA: the size should >= 1024 and <= 16384 bits.
  • DSA: the size should be 1024 bits.
  • EcDSA: the size should be 256, 384, or 521 bits.
  • Ed25519: the size should be 256 bits.

If the key size parameter is zero, then it will use the default size to generate the key

  • RSA: 2048 bits
  • DSA: 1024 bits
  • EcDSA: 256 bits
  • Ed25519: 256 bits

Indicate the key type being stored

Serialize the keypair to the OpenSSL PEM format

If the passphrase is given (set to Some(...)), then the generated PEM key will be encrypted.

Serialize the keypair to the OpenSSL PKCS#8 PEM format

If the passphrase is given (set to Some(...)), then the generated PKCS#8 key will be encrypted.

Serialize the keypair to the OpenSSH private key format

If the passphrase is given (set to Some(...)) and cipher is not null, then the generated private key will be encrypted.

Get the comment of the key

Get the mutable reference of the key comment

Get the OpenSSH public key of the public parts

Clone the public parts of the key pair

Trait Implementations

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

The size in bits of the key

The key name of the key

Sign the data with the key, returning the “detached” signature

Verify the data with a detached signature, returning true if the signature is not malformed

Return the binary representation of the public key

Hash the blob of the public key to generate the fingerprint

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.