Struct rsa::RsaPrivateKey
source · pub struct RsaPrivateKey { /* private fields */ }
Expand description
Represents a whole RSA key, public and private parts.
Implementations
sourceimpl 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>
) -> Result<RsaPrivateKey>
pub fn from_components(
n: BigUint,
e: BigUint,
d: BigUint,
primes: Vec<BigUint>
) -> Result<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 occasionally 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 appropriate 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_with_rng<R: RngCore + CryptoRng>(
&self,
rng: &mut R,
padding: PaddingScheme,
digest_in: &[u8]
) -> Result<Vec<u8>>
pub fn sign_with_rng<R: RngCore + CryptoRng>(
&self,
rng: &mut R,
padding: PaddingScheme,
digest_in: &[u8]
) -> Result<Vec<u8>>
Sign the given digest using the provided rng
Use rng
for signature process.
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.
Methods from Deref<Target = RsaPublicKey>
pub const MIN_PUB_EXPONENT: u64 = 2u64
pub const MAX_PUB_EXPONENT: u64 = 8_589_934_591u64
pub const MAX_SIZE: usize = 4_096usize
Trait Implementations
sourceimpl<D> AsRef<RsaPrivateKey> for BlindedSigningKey<D>where
D: Digest,
impl<D> AsRef<RsaPrivateKey> for BlindedSigningKey<D>where
D: Digest,
sourcefn as_ref(&self) -> &RsaPrivateKey
fn as_ref(&self) -> &RsaPrivateKey
sourceimpl<D> AsRef<RsaPrivateKey> for SigningKey<D>where
D: Digest,
impl<D> AsRef<RsaPrivateKey> for SigningKey<D>where
D: Digest,
sourcefn as_ref(&self) -> &RsaPrivateKey
fn as_ref(&self) -> &RsaPrivateKey
sourceimpl<D> AsRef<RsaPrivateKey> for SigningKey<D>where
D: Digest,
impl<D> AsRef<RsaPrivateKey> for SigningKey<D>where
D: Digest,
sourcefn as_ref(&self) -> &RsaPrivateKey
fn as_ref(&self) -> &RsaPrivateKey
sourceimpl Clone for RsaPrivateKey
impl Clone for RsaPrivateKey
sourcefn clone(&self) -> RsaPrivateKey
fn clone(&self) -> RsaPrivateKey
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresourceimpl Debug for RsaPrivateKey
impl Debug for RsaPrivateKey
sourceimpl DecodePrivateKey for RsaPrivateKey
impl DecodePrivateKey for RsaPrivateKey
sourcefn from_pkcs8_der(bytes: &[u8]) -> Result<Self, Error>
fn from_pkcs8_der(bytes: &[u8]) -> Result<Self, Error>
sourcefn from_pkcs8_pem(s: &str) -> Result<Self, Error>
fn from_pkcs8_pem(s: &str) -> Result<Self, Error>
sourceimpl Deref for RsaPrivateKey
impl Deref for RsaPrivateKey
type Target = RsaPublicKey
type Target = RsaPublicKey
sourcefn deref(&self) -> &RsaPublicKey
fn deref(&self) -> &RsaPublicKey
sourceimpl<'de> Deserialize<'de> for RsaPrivateKey
impl<'de> Deserialize<'de> for RsaPrivateKey
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
sourceimpl Drop for RsaPrivateKey
impl Drop for RsaPrivateKey
sourceimpl EncodePrivateKey for RsaPrivateKey
impl EncodePrivateKey for RsaPrivateKey
sourcefn to_pkcs8_der(&self) -> Result<SecretDocument>
fn to_pkcs8_der(&self) -> Result<SecretDocument>
SecretDocument
] containing a PKCS#8-encoded private key.sourcefn to_pkcs8_pem(
&self,
line_ending: LineEnding
) -> Result<Zeroizing<String>, Error>
fn to_pkcs8_pem(
&self,
line_ending: LineEnding
) -> Result<Zeroizing<String>, Error>
LineEnding
].sourceimpl From<&RsaPrivateKey> for RsaPublicKey
impl From<&RsaPrivateKey> for RsaPublicKey
sourcefn from(private_key: &RsaPrivateKey) -> Self
fn from(private_key: &RsaPrivateKey) -> Self
sourceimpl<D> From<BlindedSigningKey<D>> for RsaPrivateKeywhere
D: Digest,
impl<D> From<BlindedSigningKey<D>> for RsaPrivateKeywhere
D: Digest,
sourcefn from(key: BlindedSigningKey<D>) -> Self
fn from(key: BlindedSigningKey<D>) -> Self
sourceimpl<D> From<RsaPrivateKey> for BlindedSigningKey<D>where
D: Digest,
impl<D> From<RsaPrivateKey> for BlindedSigningKey<D>where
D: Digest,
sourcefn from(key: RsaPrivateKey) -> Self
fn from(key: RsaPrivateKey) -> Self
sourceimpl From<RsaPrivateKey> for RsaPublicKey
impl From<RsaPrivateKey> for RsaPublicKey
sourcefn from(private_key: RsaPrivateKey) -> Self
fn from(private_key: RsaPrivateKey) -> Self
sourceimpl<D> From<RsaPrivateKey> for SigningKey<D>where
D: Digest,
impl<D> From<RsaPrivateKey> for SigningKey<D>where
D: Digest,
sourcefn from(key: RsaPrivateKey) -> Self
fn from(key: RsaPrivateKey) -> Self
sourceimpl<D> From<RsaPrivateKey> for SigningKey<D>where
D: Digest,
impl<D> From<RsaPrivateKey> for SigningKey<D>where
D: Digest,
sourcefn from(key: RsaPrivateKey) -> Self
fn from(key: RsaPrivateKey) -> Self
sourceimpl<D> From<SigningKey<D>> for RsaPrivateKeywhere
D: Digest,
impl<D> From<SigningKey<D>> for RsaPrivateKeywhere
D: Digest,
sourcefn from(key: SigningKey<D>) -> Self
fn from(key: SigningKey<D>) -> Self
sourceimpl<D> From<SigningKey<D>> for RsaPrivateKeywhere
D: Digest,
impl<D> From<SigningKey<D>> for RsaPrivateKeywhere
D: Digest,
sourcefn from(key: SigningKey<D>) -> Self
fn from(key: SigningKey<D>) -> Self
sourceimpl PartialEq<RsaPrivateKey> for RsaPrivateKey
impl PartialEq<RsaPrivateKey> for RsaPrivateKey
sourcefn eq(&self, other: &RsaPrivateKey) -> bool
fn eq(&self, other: &RsaPrivateKey) -> bool
sourceimpl PublicKeyParts for RsaPrivateKey
impl PublicKeyParts for RsaPrivateKey
sourceimpl Serialize for RsaPrivateKey
impl Serialize for RsaPrivateKey
sourceimpl TryFrom<PrivateKeyInfo<'_>> for RsaPrivateKey
impl TryFrom<PrivateKeyInfo<'_>> for RsaPrivateKey
sourceimpl 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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<T> DecodeRsaPrivateKey for Twhere
T: DecodePrivateKey,
impl<T> DecodeRsaPrivateKey for Twhere
T: DecodePrivateKey,
sourcefn from_pkcs1_der(private_key: &[u8]) -> Result<T, Error>
fn from_pkcs1_der(private_key: &[u8]) -> Result<T, Error>
sourcefn from_pkcs1_pem(s: &str) -> Result<Self, Error>
fn from_pkcs1_pem(s: &str) -> Result<Self, Error>
sourceimpl<T> EncodeRsaPrivateKey for Twhere
T: EncodePrivateKey,
impl<T> EncodeRsaPrivateKey for Twhere
T: EncodePrivateKey,
sourcefn to_pkcs1_der(&self) -> Result<SecretDocument, Error>
fn to_pkcs1_der(&self) -> Result<SecretDocument, Error>
SecretDocument
] containing a PKCS#1-encoded private key.sourcefn to_pkcs1_pem(
&self,
line_ending: LineEnding
) -> Result<Zeroizing<String>, Error>
fn to_pkcs1_pem(
&self,
line_ending: LineEnding
) -> Result<Zeroizing<String>, Error>
LineEnding
].