Struct elliptic_curve::SecretKey [−][src]
pub struct SecretKey<C: Curve> { /* fields omitted */ }
zeroize
only.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
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
pub fn random(rng: impl CryptoRng + RngCore) -> Self where
C: ProjectiveArithmetic,
Scalar<C>: Zeroize,
This is supported on crate feature arithmetic
only.
pub fn random(rng: impl CryptoRng + RngCore) -> Self where
C: ProjectiveArithmetic,
Scalar<C>: Zeroize,
arithmetic
only.Generate a random SecretKey
Create a new secret key from a serialized scalar value
Deserialize raw private scalar as a big endian integer
Expose the byte serialization of the value this SecretKey
wraps
Borrow the inner secret ScalarBytes
value.
Warning
This value is key material.
Please treat it with the care it deserves!
pub fn to_secret_scalar(&self) -> NonZeroScalar<C> where
C: Curve + ProjectiveArithmetic,
Scalar<C>: Zeroize,
This is supported on crate feature arithmetic
only.
pub fn to_secret_scalar(&self) -> NonZeroScalar<C> where
C: Curve + ProjectiveArithmetic,
Scalar<C>: Zeroize,
arithmetic
only.Get the secret scalar value for this key..
pub fn public_key(&self) -> PublicKey<C> where
C: Curve + ProjectiveArithmetic,
Scalar<C>: Zeroize,
This is supported on crate feature arithmetic
only.
pub fn public_key(&self) -> PublicKey<C> where
C: Curve + ProjectiveArithmetic,
Scalar<C>: Zeroize,
arithmetic
only.Get the PublicKey
which corresponds to this secret key
pub fn from_jwk(jwk: &JwkEcKey) -> Result<Self> where
C: JwkParameters + ValidatePublicKey,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
This is supported on crate feature jwk
only.
pub fn from_jwk(jwk: &JwkEcKey) -> Result<Self> where
C: JwkParameters + ValidatePublicKey,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
jwk
only.pub fn from_jwk_str(jwk: &str) -> Result<Self> where
C: JwkParameters + ValidatePublicKey,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
This is supported on crate feature jwk
only.
pub fn from_jwk_str(jwk: &str) -> Result<Self> where
C: JwkParameters + ValidatePublicKey,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
jwk
only.Parse a string containing a JSON Web Key (JWK) into a SecretKey
.
pub fn to_jwk(&self) -> JwkEcKey where
C: JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
Scalar<C>: Zeroize,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
This is supported on crate features arithmetic
and jwk
only.
pub fn to_jwk(&self) -> JwkEcKey where
C: JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
Scalar<C>: Zeroize,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
arithmetic
and jwk
only.Serialize this secret key as JwkEcKey
JSON Web Key (JWK).
pub fn to_jwk_string(&self) -> String where
C: JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
Scalar<C>: Zeroize,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
This is supported on crate features arithmetic
and jwk
only.
pub fn to_jwk_string(&self) -> String where
C: JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
Scalar<C>: Zeroize,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
arithmetic
and jwk
only.Serialize this secret key as JSON Web Key (JWK) string.
Trait Implementations
impl<C> From<&'_ NonZeroScalar<C>> for SecretKey<C> where
C: Curve + ProjectiveArithmetic,
This is supported on crate feature arithmetic
only.
impl<C> From<&'_ NonZeroScalar<C>> for SecretKey<C> where
C: Curve + ProjectiveArithmetic,
arithmetic
only.Performs the conversion.
Performs the conversion.
impl<C> From<&'_ SecretKey<C>> for JwkEcKey where
C: Curve + JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
Scalar<C>: Zeroize,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
This is supported on crate features arithmetic
and jwk
only.
impl<C> From<&'_ SecretKey<C>> for JwkEcKey where
C: Curve + JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
Scalar<C>: Zeroize,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
arithmetic
and jwk
only.impl<C> From<NonZeroScalar<C>> for SecretKey<C> where
C: Curve + ProjectiveArithmetic,
This is supported on crate feature arithmetic
only.
impl<C> From<NonZeroScalar<C>> for SecretKey<C> where
C: Curve + ProjectiveArithmetic,
arithmetic
only.Performs the conversion.
Performs the conversion.
impl<C> From<SecretKey<C>> for JwkEcKey where
C: Curve + JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
Scalar<C>: Zeroize,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
This is supported on crate features arithmetic
and jwk
only.
impl<C> From<SecretKey<C>> for JwkEcKey where
C: Curve + JwkParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
Scalar<C>: Zeroize,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
arithmetic
and jwk
only.impl<C> FromPrivateKey for SecretKey<C> where
C: Curve + AlgorithmParameters + ValidatePublicKey,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
This is supported on crate feature pkcs8
only.
impl<C> FromPrivateKey for SecretKey<C> where
C: Curve + AlgorithmParameters + ValidatePublicKey,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
pkcs8
only.Parse the PrivateKeyInfo
from a PKCS#8-encoded document.
Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary format). Read more
Deserialize PKCS#8 private key from a PrivateKeyDocument
.
impl<C> FromStr for SecretKey<C> where
C: Curve + AlgorithmParameters + ValidatePublicKey,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
This is supported on crate feature pem
only.
impl<C> FromStr for SecretKey<C> where
C: Curve + AlgorithmParameters + ValidatePublicKey,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
pem
only.impl<C> ToPrivateKey for SecretKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
Scalar<C>: Zeroize,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
This is supported on crate features arithmetic
and pem
only.
impl<C> ToPrivateKey for SecretKey<C> where
C: Curve + AlgorithmParameters + ProjectiveArithmetic,
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
Scalar<C>: Zeroize,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
arithmetic
and pem
only.Serialize a PrivateKeyDocument
containing a PKCS#8-encoded private key.
Serialize this private key as PEM-encoded PKCS#8.
Serialize this private key as PEM-encoded PKCS#8 with the given LineEnding
.
impl<C> TryFrom<&'_ JwkEcKey> for SecretKey<C> where
C: Curve + JwkParameters + ValidatePublicKey,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
This is supported on crate feature jwk
only.
impl<C> TryFrom<&'_ JwkEcKey> for SecretKey<C> where
C: Curve + JwkParameters + ValidatePublicKey,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
jwk
only.impl<C> TryFrom<JwkEcKey> for SecretKey<C> where
C: Curve + JwkParameters + ValidatePublicKey,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
This is supported on crate feature jwk
only.
impl<C> TryFrom<JwkEcKey> for SecretKey<C> where
C: Curve + JwkParameters + ValidatePublicKey,
UntaggedPointSize<C>: Add<U1> + ArrayLength<u8>,
UncompressedPointSize<C>: ArrayLength<u8>,
jwk
only.Auto Trait Implementations
impl<C> RefUnwindSafe for SecretKey<C> where
<<<C as Curve>::UInt as ArrayEncoding>::ByteSize as ArrayLength<u8>>::ArrayType: RefUnwindSafe,
impl<C> Unpin for SecretKey<C> where
<<<C as Curve>::UInt as ArrayEncoding>::ByteSize as ArrayLength<u8>>::ArrayType: Unpin,
impl<C> UnwindSafe for SecretKey<C> where
<<<C as Curve>::UInt as ArrayEncoding>::ByteSize as ArrayLength<u8>>::ArrayType: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = T
Should always be Self