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>
) -> 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.
Trait Implementations
sourceimpl Clone for RsaPrivateKey
impl Clone for RsaPrivateKey
sourcefn clone(&self) -> RsaPrivateKey
fn clone(&self) -> RsaPrivateKey
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl 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>
Deserialize PKCS#8 private key from ASN.1 DER-encoded data (binary format). Read more
sourcefn from_pkcs8_doc(doc: &PrivateKeyDocument) -> Result<Self, Error>
fn from_pkcs8_doc(doc: &PrivateKeyDocument) -> Result<Self, Error>
Deserialize PKCS#8 private key from a PrivateKeyDocument
.
sourcefn from_pkcs8_pem(s: &str) -> Result<Self, Error>
fn from_pkcs8_pem(s: &str) -> Result<Self, Error>
Deserialize PKCS#8-encoded private key from PEM. Read more
sourceimpl Deref for RsaPrivateKey
impl Deref for RsaPrivateKey
type Target = RsaPublicKey
type Target = RsaPublicKey
The resulting type after dereferencing.
sourcefn deref(&self) -> &RsaPublicKey
fn deref(&self) -> &RsaPublicKey
Dereferences the value.
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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Drop for RsaPrivateKey
impl Drop for RsaPrivateKey
sourceimpl EncodePrivateKey for RsaPrivateKey
impl EncodePrivateKey for RsaPrivateKey
sourcefn to_pkcs8_der(&self) -> Result<PrivateKeyDocument>
fn to_pkcs8_der(&self) -> Result<PrivateKeyDocument>
Serialize a PrivateKeyDocument
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>
Serialize this private key as PEM-encoded PKCS#8 with the given LineEnding
.
sourcefn write_pkcs8_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
fn write_pkcs8_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
Write ASN.1 DER-encoded PKCS#8 private key to the given path
sourcefn 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>
Write ASN.1 DER-encoded PKCS#8 private key to the given path
sourceimpl From<&'_ RsaPrivateKey> for RsaPublicKey
impl From<&'_ RsaPrivateKey> for RsaPublicKey
sourcefn from(private_key: &RsaPrivateKey) -> Self
fn from(private_key: &RsaPrivateKey) -> Self
Converts to this type from the input type.
sourceimpl From<RsaPrivateKey> for RsaPublicKey
impl From<RsaPrivateKey> for RsaPublicKey
sourcefn from(private_key: RsaPrivateKey) -> Self
fn from(private_key: RsaPrivateKey) -> Self
Converts to this type from the input type.
sourceimpl PartialEq<RsaPrivateKey> for RsaPrivateKey
impl PartialEq<RsaPrivateKey> for RsaPrivateKey
sourceimpl PublicKeyParts for RsaPrivateKey
impl PublicKeyParts for RsaPrivateKey
sourceimpl<'a> PublicKeyParts for &'a RsaPrivateKey
impl<'a> PublicKeyParts for &'a 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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> DecodeRsaPrivateKey for T where
T: DecodePrivateKey,
impl<T> DecodeRsaPrivateKey for T where
T: DecodePrivateKey,
sourcefn from_pkcs1_der(private_key: &[u8]) -> Result<T, Error>
fn from_pkcs1_der(private_key: &[u8]) -> Result<T, Error>
Deserialize PKCS#1 private key from ASN.1 DER-encoded data (binary format). Read more
sourcefn from_pkcs1_pem(s: &str) -> Result<Self, Error>
fn from_pkcs1_pem(s: &str) -> Result<Self, Error>
Deserialize PKCS#1-encoded private key from PEM. Read more
sourceimpl<T> EncodeRsaPrivateKey for T where
T: EncodePrivateKey,
impl<T> EncodeRsaPrivateKey for T where
T: EncodePrivateKey,
sourcefn to_pkcs1_der(&self) -> Result<RsaPrivateKeyDocument, Error>
fn to_pkcs1_der(&self) -> Result<RsaPrivateKeyDocument, Error>
Serialize a RsaPrivateKeyDocument
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>
Serialize this private key as PEM-encoded PKCS#1 with the given LineEnding
.
sourcefn write_pkcs1_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
fn write_pkcs1_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>
Write ASN.1 DER-encoded PKCS#1 private key to the given path.
sourcefn write_pkcs1_pem_file(
&self,
path: impl AsRef<Path>,
line_ending: LineEnding
) -> Result<(), Error>
fn write_pkcs1_pem_file(
&self,
path: impl AsRef<Path>,
line_ending: LineEnding
) -> Result<(), Error>
Write ASN.1 DER-encoded PKCS#1 private key to the given path.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more