Struct rsa::RsaPrivateKey
source · pub struct RsaPrivateKey { /* private fields */ }
Expand description
Represents a whole RSA key, public and private parts.
Implementations§
source§impl RsaPrivateKey
impl RsaPrivateKey
sourcepub fn new<R: RngCore + CryptoRng>(
rng: &mut R,
bit_size: usize
) -> Result<RsaPrivateKey>
pub fn new<R: RngCore + CryptoRng>( rng: &mut R, bit_size: usize ) -> Result<RsaPrivateKey>
Generate a new Rsa key pair of the given bit size using the passed in rng
.
sourcepub fn new_with_exp<R: RngCore + CryptoRng>(
rng: &mut R,
bit_size: usize,
exp: &BigUint
) -> Result<RsaPrivateKey>
pub fn new_with_exp<R: RngCore + CryptoRng>( rng: &mut R, bit_size: usize, exp: &BigUint ) -> Result<RsaPrivateKey>
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: BigUint,
e: BigUint,
d: BigUint,
primes: Vec<BigUint>
) -> RsaPrivateKey
pub fn from_components( n: BigUint, e: BigUint, d: BigUint, primes: Vec<BigUint> ) -> RsaPrivateKey
Constructs an RSA key pair from the individual components.
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 occationally be useful to discard the private information entirely.
sourcepub fn precompute(&mut self) -> Result<()>
pub fn precompute(&mut self) -> Result<()>
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<BigUint>
pub fn crt_coefficient(&self) -> Option<BigUint>
Compute CRT coefficient: (1/q) mod p
.
sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Performs basic sanity checks on the key.
Returns Ok(())
if everything is good, otherwise an approriate error.
sourcepub fn decrypt(
&self,
padding: PaddingScheme,
ciphertext: &[u8]
) -> Result<Vec<u8>>
pub fn decrypt( &self, padding: PaddingScheme, ciphertext: &[u8] ) -> Result<Vec<u8>>
Decrypt the given message.
sourcepub fn decrypt_blinded<R: RngCore + CryptoRng>(
&self,
rng: &mut R,
padding: PaddingScheme,
ciphertext: &[u8]
) -> Result<Vec<u8>>
pub fn decrypt_blinded<R: RngCore + CryptoRng>( &self, rng: &mut R, padding: PaddingScheme, ciphertext: &[u8] ) -> Result<Vec<u8>>
Decrypt the given message.
Uses rng
to blind the decryption process.
sourcepub fn sign(&self, padding: PaddingScheme, digest_in: &[u8]) -> Result<Vec<u8>>
pub fn sign(&self, padding: PaddingScheme, digest_in: &[u8]) -> Result<Vec<u8>>
Sign the given digest.
sourcepub fn sign_blinded<R: RngCore + CryptoRng>(
&self,
rng: &mut R,
padding: PaddingScheme,
digest_in: &[u8]
) -> Result<Vec<u8>>
pub fn sign_blinded<R: RngCore + CryptoRng>( &self, rng: &mut R, padding: PaddingScheme, digest_in: &[u8] ) -> Result<Vec<u8>>
Sign the given digest.
Use rng
for blinding.
Trait Implementations§
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 DecodePrivateKey for RsaPrivateKey
impl DecodePrivateKey for RsaPrivateKey
source§fn from_pkcs8_der(bytes: &[u8]) -> Result<Self, Error>
fn from_pkcs8_der(bytes: &[u8]) -> Result<Self, Error>
source§fn from_pkcs8_doc(doc: &PrivateKeyDocument) -> Result<Self, Error>
fn from_pkcs8_doc(doc: &PrivateKeyDocument) -> Result<Self, Error>
PrivateKeyDocument
.source§fn from_pkcs8_pem(s: &str) -> Result<Self, Error>
fn from_pkcs8_pem(s: &str) -> Result<Self, Error>
source§impl Deref for RsaPrivateKey
impl Deref for RsaPrivateKey
§type Target = RsaPublicKey
type Target = RsaPublicKey
source§fn deref(&self) -> &RsaPublicKey
fn deref(&self) -> &RsaPublicKey
source§impl Drop for RsaPrivateKey
impl Drop for RsaPrivateKey
source§impl EncodePrivateKey for RsaPrivateKey
impl EncodePrivateKey for RsaPrivateKey
source§fn to_pkcs8_der(&self) -> Result<PrivateKeyDocument>
fn to_pkcs8_der(&self) -> Result<PrivateKeyDocument>
PrivateKeyDocument
containing a PKCS#8-encoded private key.source§fn to_pkcs8_pem(
&self,
line_ending: LineEnding
) -> Result<Zeroizing<String>, Error>
fn to_pkcs8_pem( &self, line_ending: LineEnding ) -> Result<Zeroizing<String>, Error>
LineEnding
.source§fn write_pkcs8_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
fn write_pkcs8_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
source§fn write_pkcs8_pem_file(
&self,
path: impl AsRef<Path>,
line_ending: LineEnding
) -> Result<(), Error>
fn write_pkcs8_pem_file( &self, path: impl AsRef<Path>, line_ending: LineEnding ) -> Result<(), Error>
source§impl From<&RsaPrivateKey> for RsaPublicKey
impl From<&RsaPrivateKey> for RsaPublicKey
source§fn from(private_key: &RsaPrivateKey) -> Self
fn from(private_key: &RsaPrivateKey) -> Self
source§impl From<RsaPrivateKey> for RsaPublicKey
impl From<RsaPrivateKey> for RsaPublicKey
source§fn from(private_key: RsaPrivateKey) -> Self
fn from(private_key: RsaPrivateKey) -> Self
source§impl PartialEq for RsaPrivateKey
impl PartialEq for RsaPrivateKey
source§fn eq(&self, other: &RsaPrivateKey) -> bool
fn eq(&self, other: &RsaPrivateKey) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a> PublicKeyParts for &'a RsaPrivateKey
impl<'a> PublicKeyParts for &'a RsaPrivateKey
source§impl PublicKeyParts for RsaPrivateKey
impl PublicKeyParts for RsaPrivateKey
source§impl TryFrom<PrivateKeyInfo<'_>> for RsaPrivateKey
impl TryFrom<PrivateKeyInfo<'_>> for RsaPrivateKey
source§impl Zeroize for RsaPrivateKey
impl Zeroize for RsaPrivateKey
impl Eq for RsaPrivateKey
Auto Trait Implementations§
impl RefUnwindSafe for RsaPrivateKey
impl Send for RsaPrivateKey
impl Sync for RsaPrivateKey
impl Unpin for RsaPrivateKey
impl UnwindSafe for RsaPrivateKey
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> DecodeRsaPrivateKey for Twhere
T: DecodePrivateKey,
impl<T> DecodeRsaPrivateKey for Twhere
T: DecodePrivateKey,
source§fn from_pkcs1_der(private_key: &[u8]) -> Result<T, Error>
fn from_pkcs1_der(private_key: &[u8]) -> Result<T, Error>
source§fn from_pkcs1_pem(s: &str) -> Result<Self, Error>
fn from_pkcs1_pem(s: &str) -> Result<Self, Error>
source§impl<T> EncodeRsaPrivateKey for Twhere
T: EncodePrivateKey,
impl<T> EncodeRsaPrivateKey for Twhere
T: EncodePrivateKey,
source§fn to_pkcs1_der(&self) -> Result<RsaPrivateKeyDocument, Error>
fn to_pkcs1_der(&self) -> Result<RsaPrivateKeyDocument, Error>
RsaPrivateKeyDocument
containing a PKCS#1-encoded private key.source§fn to_pkcs1_pem(
&self,
line_ending: LineEnding
) -> Result<Zeroizing<String>, Error>
fn to_pkcs1_pem( &self, line_ending: LineEnding ) -> Result<Zeroizing<String>, Error>
LineEnding
.