pub struct PrivateKey { /* private fields */ }Expand description
An Ed25519 secret key
Implementations§
Source§impl PrivateKey
impl PrivateKey
Sourcepub fn generate_using_rng<R: CryptoRng + Rng>(rng: &mut R) -> Self
pub fn generate_using_rng<R: CryptoRng + Rng>(rng: &mut R) -> Self
Create a new random secret Ed25519 key using specified RNG
Sourcepub fn generate_from_seed(seed: &[u8]) -> Self
pub fn generate_from_seed(seed: &[u8]) -> Self
Generate a key using an input seed
§Warning
For security the seed should be at least 256 bits and randomly generated
Sourcepub fn sign_message(&self, msg: &[u8]) -> [u8; 64]
pub fn sign_message(&self, msg: &[u8]) -> [u8; 64]
Sign a message and return a signature
This is the non-prehashed variant of Ed25519
Sourcepub fn public_key(&self) -> PublicKey
pub fn public_key(&self) -> PublicKey
Return the public key associated with this secret key
Sourcepub fn serialize_raw(&self) -> [u8; 32]
pub fn serialize_raw(&self) -> [u8; 32]
Serialize the Ed25519 secret key
This returns the 32-byte encoding of the seed value which is used to derive the secret scalar
Sourcepub fn deserialize_raw(bytes: &[u8]) -> Result<Self, PrivateKeyDecodingError>
pub fn deserialize_raw(bytes: &[u8]) -> Result<Self, PrivateKeyDecodingError>
Deserialize an Ed25519 private key from raw format
This is just the plain 32 byte random seed from which the internal key material is derived
This corresponds with the format used by PrivateKey::serialize_raw
Sourcepub fn deserialize_raw_32(bytes: &[u8; 32]) -> Self
pub fn deserialize_raw_32(bytes: &[u8; 32]) -> Self
Deserialize an Ed25519 private key from raw format
This is just the plain 32 byte random seed from which the internal key material is derived
This corresponds with the format used by PrivateKey::serialize_raw
Sourcepub fn serialize_pkcs8(&self, format: PrivateKeyFormat) -> Vec<u8> ⓘ
pub fn serialize_pkcs8(&self, format: PrivateKeyFormat) -> Vec<u8> ⓘ
Serialize the Ed25519 secret key in PKCS8 format
The details of the formatting are specified using the argument
Sourcepub fn deserialize_pkcs8(bytes: &[u8]) -> Result<Self, PrivateKeyDecodingError>
pub fn deserialize_pkcs8(bytes: &[u8]) -> Result<Self, PrivateKeyDecodingError>
Deserialize an Ed25519 private key from PKCS8 format
Both v1 and v2 PKCS8 encodings are accepted. The only difference is that v2 includes the public key as well. This also accepts the buggy format used by ring 0.16.
This corresponds with the format used by PrivateKey::serialize_pkcs8
Sourcepub fn serialize_pkcs8_pem(&self, format: PrivateKeyFormat) -> String
pub fn serialize_pkcs8_pem(&self, format: PrivateKeyFormat) -> String
Serialize the Ed25519 secret key in PKCS8 v2 format with PEM encoding
The details of the formatting are specified using the argument
Sourcepub fn deserialize_pkcs8_pem(pem: &str) -> Result<Self, PrivateKeyDecodingError>
pub fn deserialize_pkcs8_pem(pem: &str) -> Result<Self, PrivateKeyDecodingError>
Deserialize an Ed25519 private key from PKCS8 PEM format
Both v1 and v2 PKCS8 encodings are accepted
This corresponds with the format used by PrivateKey::serialize_pkcs8_pem
Sourcepub fn derive_subkey(
&self,
derivation_path: &DerivationPath,
) -> (DerivedPrivateKey, [u8; 32])
pub fn derive_subkey( &self, derivation_path: &DerivationPath, ) -> (DerivedPrivateKey, [u8; 32])
Derive a private key from this private key using a derivation path
This is the same derivation system used by the Internet Computer when deriving subkeys for threshold Ed25519
Note that this function returns a DerivedPrivateKey rather than Self, and that DerivedPrivateKey can sign messages but cannot be serialized. This is due to the definition of Ed25519 private keys, which is incompatible with additive derivation.
Sourcepub fn derive_subkey_with_chain_code(
&self,
derivation_path: &DerivationPath,
chain_code: &[u8; 32],
) -> (DerivedPrivateKey, [u8; 32])
pub fn derive_subkey_with_chain_code( &self, derivation_path: &DerivationPath, chain_code: &[u8; 32], ) -> (DerivedPrivateKey, [u8; 32])
Derive a private key from this private key using a derivation path and chain code
This is the same derivation system used by the Internet Computer when deriving subkeys for threshold Ed25519
Note that this function returns a DerivedPrivateKey rather than Self, and that DerivedPrivateKey can sign messages but cannot be serialized. This is due to the definition of Ed25519 private keys, which is incompatible with additive derivation.
Trait Implementations§
Source§impl Clone for PrivateKey
impl Clone for PrivateKey
Source§fn clone(&self) -> PrivateKey
fn clone(&self) -> PrivateKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more