pub struct PrivateKey { /* private fields */ }
Expand description
A private key for use (only) with agree
. The
signature of agree
allows PrivateKey
to be
used for more than one key agreement.
Implementations§
Source§impl PrivateKey
impl PrivateKey
Sourcepub fn generate(alg: &'static Algorithm) -> Result<Self, Unspecified>
pub fn generate(alg: &'static Algorithm) -> Result<Self, Unspecified>
Generate a new private key for the given algorithm.
§Errors
error::Unspecified
when operation fails due to internal error.
Sourcepub fn from_private_key_der(
alg: &'static Algorithm,
key_bytes: &[u8],
) -> Result<Self, KeyRejected>
pub fn from_private_key_der( alg: &'static Algorithm, key_bytes: &[u8], ) -> Result<Self, KeyRejected>
Deserializes a DER-encoded private key structure to produce a agreement::PrivateKey
.
This function is typically used to deserialize RFC 5915 encoded private keys, but it will
attempt to automatically detect other key formats. This function supports unencrypted
PKCS#8 PrivateKeyInfo
structures as well as key type specific formats.
X25519 keys are not supported. See PrivateKey::as_der
.
§Errors
error::KeyRejected
if parsing failed or key otherwise unacceptable.
§Panics
Sourcepub fn from_private_key(
alg: &'static Algorithm,
key_bytes: &[u8],
) -> Result<Self, KeyRejected>
pub fn from_private_key( alg: &'static Algorithm, key_bytes: &[u8], ) -> Result<Self, KeyRejected>
Constructs an ECDH key from private key bytes
The private key must encoded as a big-endian fixed-length integer. For example, a P-256 private key must be 32 bytes prefixed with leading zeros as needed.
§Errors
error::KeyRejected
if parsing failed or key otherwise unacceptable.
Sourcepub fn compute_public_key(&self) -> Result<PublicKey, Unspecified>
pub fn compute_public_key(&self) -> Result<PublicKey, Unspecified>
Computes the public key from the private key.
§Errors
error::Unspecified
when operation fails due to internal error.
Trait Implementations§
Source§impl AsBigEndian<Curve25519SeedBin<'static>> for PrivateKey
impl AsBigEndian<Curve25519SeedBin<'static>> for PrivateKey
Source§fn as_be_bytes(&self) -> Result<Curve25519SeedBin<'static>, Unspecified>
fn as_be_bytes(&self) -> Result<Curve25519SeedBin<'static>, Unspecified>
Exposes the seed encoded as a big-endian fixed-length integer.
Only X25519 is supported.
§Errors
error::Unspecified
if serialization failed.
Source§impl AsBigEndian<EcPrivateKeyBin<'static>> for PrivateKey
impl AsBigEndian<EcPrivateKeyBin<'static>> for PrivateKey
Source§fn as_be_bytes(&self) -> Result<EcPrivateKeyBin<'static>, Unspecified>
fn as_be_bytes(&self) -> Result<EcPrivateKeyBin<'static>, Unspecified>
Exposes the private key encoded as a big-endian fixed-length integer.
X25519 is not supported.
§Errors
error::Unspecified
if serialization failed.
Source§impl AsDer<EcPrivateKeyRfc5915Der<'static>> for PrivateKey
impl AsDer<EcPrivateKeyRfc5915Der<'static>> for PrivateKey
Source§fn as_der(&self) -> Result<EcPrivateKeyRfc5915Der<'static>, Unspecified>
fn as_der(&self) -> Result<EcPrivateKeyRfc5915Der<'static>, Unspecified>
Serializes the key as a DER-encoded ECPrivateKey
(RFC 5915) structure.
X25519 is not supported.
§Errors
error::Unspecified
if serialization failed.