pub struct RsaPrivateKey { /* private fields */ }rsa only.Expand description
Represents a whole RSA key, public and private parts.
Implementations§
Source§impl RsaPrivateKey
impl RsaPrivateKey
Sourcepub fn new<R>(rng: &mut R, bit_size: usize) -> Result<RsaPrivateKey, Error>
pub fn new<R>(rng: &mut R, bit_size: usize) -> Result<RsaPrivateKey, Error>
Generate a new RSA key pair with a modulus of the given bit size using the passed in rng.
§Errors
- If
bit_sizeis lower than the minimum 1024-bits.
Sourcepub fn new_with_exp<R>(
rng: &mut R,
bit_size: usize,
exp: BoxedUint,
) -> Result<RsaPrivateKey, Error>
pub fn new_with_exp<R>( rng: &mut R, bit_size: usize, exp: BoxedUint, ) -> Result<RsaPrivateKey, Error>
Generate a new RSA key pair of the given bit size and the public exponent
using the passed in rng.
Unless you have specific needs, you should use RsaPrivateKey::new instead.
Sourcepub fn from_components(
n: BoxedUint,
e: BoxedUint,
d: BoxedUint,
primes: Vec<BoxedUint>,
) -> Result<RsaPrivateKey, Error>
pub fn from_components( n: BoxedUint, e: BoxedUint, d: BoxedUint, primes: Vec<BoxedUint>, ) -> Result<RsaPrivateKey, Error>
Constructs an RSA key pair from individual components:
n: RSA moduluse: public exponent (i.e. encrypting exponent)d: private exponent (i.e. decrypting exponent)primes: prime factors ofn: typically two primespandq. More than two primes can be provided for multiprime RSA, however this is generally not recommended. If noprimesare provided, a prime factor recovery algorithm will be employed to attempt to recover the factors (as described in NIST SP 800-56B Revision 2 Appendix C.2). This algorithm only works if there are just two prime factorspandq(as opposed to multiprime), andeis between 2^16 and 2^256.
Sourcepub fn from_p_q(
p: BoxedUint,
q: BoxedUint,
public_exponent: BoxedUint,
) -> Result<RsaPrivateKey, Error>
pub fn from_p_q( p: BoxedUint, q: BoxedUint, public_exponent: BoxedUint, ) -> Result<RsaPrivateKey, Error>
Constructs an RSA key pair from its two primes p and q.
This will rebuild the private exponent and the modulus.
Private exponent will be rebuilt using the method defined in NIST 800-56B Section 6.2.1.
Sourcepub fn from_primes(
primes: Vec<BoxedUint>,
public_exponent: BoxedUint,
) -> Result<RsaPrivateKey, Error>
pub fn from_primes( primes: Vec<BoxedUint>, public_exponent: BoxedUint, ) -> Result<RsaPrivateKey, Error>
Constructs an RSA key pair from its primes.
This will rebuild the private exponent and the modulus.
Sourcepub fn to_public_key(&self) -> RsaPublicKey
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.
Sourcepub fn precompute(&mut self) -> Result<(), Error>
pub fn precompute(&mut self) -> Result<(), Error>
Performs some calculations to speed up private key operations.
Sourcepub fn clear_precomputed(&mut self)
pub fn clear_precomputed(&mut self)
Clears precomputed values by setting to None
Sourcepub fn crt_coefficient(&self) -> Option<BoxedUint>
pub fn crt_coefficient(&self) -> Option<BoxedUint>
Compute CRT coefficient: (1/q) mod p.
Sourcepub fn validate(&self) -> Result<(), Error>
pub fn validate(&self) -> Result<(), Error>
Performs basic sanity checks on the key.
Returns Ok(()) if everything is good, otherwise an appropriate error.
Sourcepub fn decrypt<P>(
&self,
padding: P,
ciphertext: &[u8],
) -> Result<Vec<u8>, Error>where
P: PaddingScheme,
pub fn decrypt<P>(
&self,
padding: P,
ciphertext: &[u8],
) -> Result<Vec<u8>, Error>where
P: PaddingScheme,
Decrypt the given message.
Sourcepub fn decrypt_blinded<R, P>(
&self,
rng: &mut R,
padding: P,
ciphertext: &[u8],
) -> Result<Vec<u8>, Error>
pub fn decrypt_blinded<R, P>( &self, rng: &mut R, padding: P, ciphertext: &[u8], ) -> Result<Vec<u8>, Error>
Decrypt the given message.
Uses rng to blind the decryption process.
Sourcepub fn sign<S>(&self, padding: S, digest_in: &[u8]) -> Result<Vec<u8>, Error>where
S: SignatureScheme,
pub fn sign<S>(&self, padding: S, digest_in: &[u8]) -> Result<Vec<u8>, Error>where
S: SignatureScheme,
Sign the given digest.
Sourcepub fn sign_with_rng<R, S>(
&self,
rng: &mut R,
padding: S,
digest_in: &[u8],
) -> Result<Vec<u8>, Error>
pub fn sign_with_rng<R, S>( &self, rng: &mut R, padding: S, digest_in: &[u8], ) -> Result<Vec<u8>, Error>
Sign the given digest using the provided rng, which is used in the
following ways depending on the SignatureScheme:
Pkcs1v15Signpadding: uses the RNG to mask the private key operation with random blinding, which helps mitigate sidechannel attacks.Pssalways requires randomness. UsePss::newfor a standard RSASSA-PSS signature, orPss::new_blindedfor RSA-BSSA blind signatures.
Trait Implementations§
Source§impl AsRef<RsaPublicKey> for RsaPrivateKey
impl AsRef<RsaPublicKey> for RsaPrivateKey
Source§fn as_ref(&self) -> &RsaPublicKey
fn as_ref(&self) -> &RsaPublicKey
Source§impl Clone for RsaPrivateKey
impl Clone for RsaPrivateKey
Source§fn clone(&self) -> RsaPrivateKey
fn clone(&self) -> RsaPrivateKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RsaPrivateKey
impl Debug for RsaPrivateKey
Source§impl Drop for RsaPrivateKey
impl Drop for RsaPrivateKey
Source§impl<'a> From<&'a RsaPrivateKey> for JsonWebKey<'a>
⚠ Warning. Contrary to RFC 7518, this implementation does not set dp, dq, and qi
fields in the JWK root object, as well as d and t fields for additional factors
(i.e., in the oth array).
impl<'a> From<&'a RsaPrivateKey> for JsonWebKey<'a>
⚠ Warning. Contrary to RFC 7518, this implementation does not set dp, dq, and qi
fields in the JWK root object, as well as d and t fields for additional factors
(i.e., in the oth array).
Source§fn from(key: &'a RsaPrivateKey) -> JsonWebKey<'a>
fn from(key: &'a RsaPrivateKey) -> JsonWebKey<'a>
Source§impl From<&RsaPrivateKey> for RsaPublicKey
impl From<&RsaPrivateKey> for RsaPublicKey
Source§fn from(private_key: &RsaPrivateKey) -> RsaPublicKey
fn from(private_key: &RsaPrivateKey) -> RsaPublicKey
Source§impl<D> From<BlindedSigningKey<D>> for RsaPrivateKeywhere
D: Digest,
impl<D> From<BlindedSigningKey<D>> for RsaPrivateKeywhere
D: Digest,
Source§fn from(key: BlindedSigningKey<D>) -> RsaPrivateKey
fn from(key: BlindedSigningKey<D>) -> RsaPrivateKey
Source§impl From<RsaPrivateKey> for RsaPublicKey
impl From<RsaPrivateKey> for RsaPublicKey
Source§fn from(private_key: RsaPrivateKey) -> RsaPublicKey
fn from(private_key: RsaPrivateKey) -> RsaPublicKey
Source§impl<D> From<SigningKey<D>> for RsaPrivateKeywhere
D: Digest,
impl<D> From<SigningKey<D>> for RsaPrivateKeywhere
D: Digest,
Source§fn from(key: SigningKey<D>) -> RsaPrivateKey
fn from(key: SigningKey<D>) -> RsaPrivateKey
Source§impl<D> From<SigningKey<D>> for RsaPrivateKeywhere
D: Digest,
impl<D> From<SigningKey<D>> for RsaPrivateKeywhere
D: Digest,
Source§fn from(key: SigningKey<D>) -> RsaPrivateKey
fn from(key: SigningKey<D>) -> RsaPrivateKey
Source§impl Hash for RsaPrivateKey
impl Hash for RsaPrivateKey
Source§impl PartialEq for RsaPrivateKey
impl PartialEq for RsaPrivateKey
Source§impl PrivateKeyParts for RsaPrivateKey
impl PrivateKeyParts for RsaPrivateKey
Source§fn crt_values(&self) -> Option<&[CrtValue]>
fn crt_values(&self) -> Option<&[CrtValue]>
Source§impl PublicKeyParts for RsaPrivateKey
impl PublicKeyParts for RsaPrivateKey
Source§impl TryFrom<&JsonWebKey<'_>> for RsaPrivateKey
⚠ Warning. Contrary to RFC 7518 (at least, in spirit), this conversion ignores
dp, dq, and qi fields from JWK, as well as d and t fields for additional factors.
impl TryFrom<&JsonWebKey<'_>> for RsaPrivateKey
⚠ Warning. Contrary to RFC 7518 (at least, in spirit), this conversion ignores
dp, dq, and qi fields from JWK, as well as d and t fields for additional factors.