pub struct SecretKey(pub RsaPrivateKey);
Expand description

An RSA secret key

Tuple Fields§

§0: RsaPrivateKey

Implementations§

source§

impl SecretKey

source

pub fn new(f0: RsaPrivateKey) -> Self

Constructs a new SecretKey.

source§

impl SecretKey

source

pub fn to_der(&self) -> Result<Vec<u8>, Error>

source

pub fn from_der(der: &[u8]) -> Result<Self, Error>

source

pub fn to_pem(&self) -> Result<String, Error>

source

pub fn from_pem(pem: &str) -> Result<Self, Error>

source

pub fn public_key(&self) -> Result<PublicKey, Error>

source

pub fn blind_sign<R: CryptoRng + RngCore>( &self, rng: &mut R, blind_msg: impl AsRef<[u8]>, _options: &Options ) -> Result<BlindSignature, Error>

Sign a blinded message

Methods from Deref<Target = RsaPrivateKey>§

source

pub fn to_public_key(&self) -> RsaPublicKey

Get the public key from the private key, cloning n and e.

Generally this is not needed since RsaPrivateKey implements the PublicKey trait, but it can occasionally be useful to discard the private information entirely.

source

pub fn dp(&self) -> Option<&BigUint>

Returns the precomputed dp value, D mod (P-1)

source

pub fn dq(&self) -> Option<&BigUint>

Returns the precomputed dq value, D mod (Q-1)

source

pub fn qinv(&self) -> Option<&BigInt>

Returns the precomputed qinv value, Q^-1 mod P

source

pub fn d(&self) -> &BigUint

Returns the private exponent of the key.

source

pub fn primes(&self) -> &[BigUint]

Returns the prime factors.

source

pub fn crt_coefficient(&self) -> Option<BigUint>

Compute CRT coefficient: (1/q) mod p.

source

pub fn validate(&self) -> Result<(), Error>

Performs basic sanity checks on the key. Returns Ok(()) if everything is good, otherwise an appropriate error.

source

pub fn decrypt<P>( &self, padding: P, ciphertext: &[u8] ) -> Result<Vec<u8, Global>, Error>where P: PaddingScheme,

Decrypt the given message.

source

pub fn decrypt_blinded<R, P>( &self, rng: &mut R, padding: P, ciphertext: &[u8] ) -> Result<Vec<u8, Global>, Error>where R: CryptoRngCore, P: PaddingScheme,

Decrypt the given message.

Uses rng to blind the decryption process.

source

pub fn sign<S>( &self, padding: S, digest_in: &[u8] ) -> Result<Vec<u8, Global>, Error>where S: SignatureScheme,

Sign the given digest.

source

pub fn sign_with_rng<R, S>( &self, rng: &mut R, padding: S, digest_in: &[u8] ) -> Result<Vec<u8, Global>, Error>where R: CryptoRngCore, S: SignatureScheme,

Sign the given digest using the provided rng, which is used in the following ways depending on the SignatureScheme:

  • Pkcs1v15Sign padding: uses the RNG to mask the private key operation with random blinding, which helps mitigate sidechannel attacks.
  • Pss always requires randomness. Use Pss::new for a standard RSASSA-PSS signature, or Pss::new_blinded for RSA-BSSA blind signatures.

Methods from Deref<Target = RsaPublicKey>§

source

pub const MIN_PUB_EXPONENT: u64 = 2u64

source

pub const MAX_PUB_EXPONENT: u64 = 8_589_934_591u64

source

pub const MAX_SIZE: usize = 4_096usize

Trait Implementations§

source§

impl AsRef<RsaPrivateKey> for SecretKey

source§

fn as_ref(&self) -> &RsaPrivateKey

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for SecretKey

source§

fn clone(&self) -> SecretKey

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SecretKey

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for SecretKey

§

type Target = RsaPrivateKey

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl From<RsaPrivateKey> for SecretKey

source§

fn from(original: RsaPrivateKey) -> SecretKey

Converts to this type from the input type.
source§

impl From<SecretKey> for RsaPrivateKey

source§

fn from(original: SecretKey) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V