pub struct SecretKey<C: Curve> { /* private fields */ }Expand description
Elliptic curve secret keys.
This type wraps a secret scalar value, helping to prevent accidental
exposure and securely erasing the value from memory when dropped
(when the zeroize feature of this crate is enabled).
§Parsing PKCS#8 Keys
PKCS#8 is a commonly used format for encoding secret keys (especially ones generated by OpenSSL).
Keys in PKCS#8 format are either binary (ASN.1 BER/DER), or PEM encoded (ASCII) and begin with the following:
-----BEGIN PRIVATE KEY-----To decode an elliptic curve private key from PKCS#8, enable the pkcs8
feature of this crate (or the pkcs8 feature of a specific RustCrypto
elliptic curve crate) and use the
[elliptic_curve::pkcs8::FromPrivateKey][FromPrivateKey]
trait to parse it.
When the pem feature of this crate (or a specific RustCrypto elliptic
curve crate) is enabled, a [FromStr] impl is also available.
Implementations§
Source§impl<C> SecretKey<C>where
C: Curve,
impl<C> SecretKey<C>where
C: Curve,
Sourcepub fn new(scalar: ScalarBytes<C>) -> Self
pub fn new(scalar: ScalarBytes<C>) -> Self
Create a new secret key from a serialized scalar value
Sourcepub fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self>
pub fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self>
Deserialize raw private scalar as a big endian integer
Sourcepub fn to_bytes(&self) -> FieldBytes<C>
pub fn to_bytes(&self) -> FieldBytes<C>
Expose the byte serialization of the value this SecretKey wraps
Sourcepub fn as_scalar_bytes(&self) -> &ScalarBytes<C>
pub fn as_scalar_bytes(&self) -> &ScalarBytes<C>
Borrow the inner secret ScalarBytes value.
§Warning
This value is key material.
Please treat it with the care it deserves!
Sourcepub fn to_secret_scalar(&self) -> NonZeroScalar<C>
pub fn to_secret_scalar(&self) -> NonZeroScalar<C>
Get the secret scalar value for this key..
Sourcepub fn public_key(&self) -> PublicKey<C>
pub fn public_key(&self) -> PublicKey<C>
Get the PublicKey which corresponds to this secret key
Trait Implementations§
Source§impl<C> From<&NonZeroScalar<C>> for SecretKey<C>where
C: Curve + ProjectiveArithmetic,
Available on crate feature arithmetic only.
impl<C> From<&NonZeroScalar<C>> for SecretKey<C>where
C: Curve + ProjectiveArithmetic,
arithmetic only.Source§fn from(scalar: &NonZeroScalar<C>) -> SecretKey<C>
fn from(scalar: &NonZeroScalar<C>) -> SecretKey<C>
Source§impl<C> From<&SecretKey<C>> for NonZeroScalar<C>where
C: Curve + ProjectiveArithmetic,
Available on crate feature zeroize only.
impl<C> From<&SecretKey<C>> for NonZeroScalar<C>where
C: Curve + ProjectiveArithmetic,
zeroize only.Source§fn from(sk: &SecretKey<C>) -> NonZeroScalar<C>
fn from(sk: &SecretKey<C>) -> NonZeroScalar<C>
Source§impl<C> From<NonZeroScalar<C>> for SecretKey<C>where
C: Curve + ProjectiveArithmetic,
Available on crate feature arithmetic only.
impl<C> From<NonZeroScalar<C>> for SecretKey<C>where
C: Curve + ProjectiveArithmetic,
arithmetic only.Source§fn from(scalar: NonZeroScalar<C>) -> SecretKey<C>
fn from(scalar: NonZeroScalar<C>) -> SecretKey<C>
Source§impl<C> From<SecretKey<C>> for NonZeroScalar<C>where
C: Curve + ProjectiveArithmetic,
Available on crate feature zeroize only.
impl<C> From<SecretKey<C>> for NonZeroScalar<C>where
C: Curve + ProjectiveArithmetic,
zeroize only.