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: Rng>(rng: &mut R, bit_size: usize) -> Result<RsaPrivateKey>
This is supported on crate feature alloc
only.
pub fn new<R: Rng>(rng: &mut R, bit_size: usize) -> Result<RsaPrivateKey>
alloc
only.Generate a new Rsa key pair of the given bit size using the passed in rng
.
sourcepub fn new_with_exp<R: Rng>(
rng: &mut R,
bit_size: usize,
exp: &BigUint
) -> Result<RsaPrivateKey>
This is supported on crate feature alloc
only.
pub fn new_with_exp<R: Rng>(
rng: &mut R,
bit_size: usize,
exp: &BigUint
) -> Result<RsaPrivateKey>
alloc
only.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
This is supported on crate feature alloc
only.
pub fn from_components(
n: BigUint,
e: BigUint,
d: BigUint,
primes: Vec<BigUint>
) -> RsaPrivateKey
alloc
only.Constructs an RSA key pair from the individual components.
sourcepub fn to_public_key(&self) -> RsaPublicKey
This is supported on crate feature alloc
only.
pub fn to_public_key(&self) -> RsaPublicKey
alloc
only.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<()>
This is supported on crate feature alloc
only.
pub fn precompute(&mut self) -> Result<()>
alloc
only.Performs some calculations to speed up private key operations.
sourcepub fn clear_precomputed(&mut self)
This is supported on crate feature alloc
only.
pub fn clear_precomputed(&mut self)
alloc
only.Clears precomputed values by setting to None
sourcepub fn d(&self) -> &BigUint
This is supported on crate feature alloc
only.
pub fn d(&self) -> &BigUint
alloc
only.Returns the private exponent of the key.
sourcepub fn primes(&self) -> &[BigUint]
This is supported on crate feature alloc
only.
pub fn primes(&self) -> &[BigUint]
alloc
only.Returns the prime factors.
sourcepub fn validate(&self) -> Result<()>
This is supported on crate feature alloc
only.
pub fn validate(&self) -> Result<()>
alloc
only.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>>
This is supported on crate feature alloc
only.
pub fn decrypt(
&self,
padding: PaddingScheme,
ciphertext: &[u8]
) -> Result<Vec<u8>>
alloc
only.Decrypt the given message.
sourcepub fn decrypt_blinded<R: Rng>(
&self,
rng: &mut R,
padding: PaddingScheme,
ciphertext: &[u8]
) -> Result<Vec<u8>>
This is supported on crate feature alloc
only.
pub fn decrypt_blinded<R: Rng>(
&self,
rng: &mut R,
padding: PaddingScheme,
ciphertext: &[u8]
) -> Result<Vec<u8>>
alloc
only.Decrypt the given message.
Uses rng
to blind the decryption process.
Trait Implementations
sourceimpl Clone for RsaPrivateKey
This is supported on crate feature alloc
only.
impl Clone for RsaPrivateKey
alloc
only.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
This is supported on crate feature alloc
only.
impl Debug for RsaPrivateKey
alloc
only.sourceimpl DecodePrivateKey for RsaPrivateKey
This is supported on crate feature alloc
only.
impl DecodePrivateKey for RsaPrivateKey
alloc
only.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
This is supported on crate feature alloc
only.
impl Deref for RsaPrivateKey
alloc
only.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
This is supported on crate feature alloc
only.
impl<'de> Deserialize<'de> for RsaPrivateKey
alloc
only.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
This is supported on crate feature alloc
only.
impl Drop for RsaPrivateKey
alloc
only.sourceimpl EncodePrivateKey for RsaPrivateKey
This is supported on crate feature alloc
only.
impl EncodePrivateKey for RsaPrivateKey
alloc
only.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
This is supported on crate feature alloc
only.
impl From<&'_ RsaPrivateKey> for RsaPublicKey
alloc
only.sourcefn from(private_key: &RsaPrivateKey) -> Self
fn from(private_key: &RsaPrivateKey) -> Self
Performs the conversion.
sourceimpl From<RsaPrivateKey> for RsaPublicKey
This is supported on crate feature alloc
only.
impl From<RsaPrivateKey> for RsaPublicKey
alloc
only.sourcefn from(private_key: RsaPrivateKey) -> Self
fn from(private_key: RsaPrivateKey) -> Self
Performs the conversion.
sourceimpl PartialEq<RsaPrivateKey> for RsaPrivateKey
This is supported on crate feature alloc
only.
impl PartialEq<RsaPrivateKey> for RsaPrivateKey
alloc
only.sourceimpl PublicKeyParts for RsaPrivateKey
This is supported on crate feature alloc
only.
impl PublicKeyParts for RsaPrivateKey
alloc
only.sourceimpl<'a> PublicKeyParts for &'a RsaPrivateKey
This is supported on crate feature alloc
only.
impl<'a> PublicKeyParts for &'a RsaPrivateKey
alloc
only.sourceimpl Serialize for RsaPrivateKey
This is supported on crate feature alloc
only.
impl Serialize for RsaPrivateKey
alloc
only.sourceimpl TryFrom<PrivateKeyInfo<'_>> for RsaPrivateKey
This is supported on crate feature alloc
only.
impl TryFrom<PrivateKeyInfo<'_>> for RsaPrivateKey
alloc
only.sourceimpl Zeroize for RsaPrivateKey
This is supported on crate feature alloc
only.
impl Zeroize for RsaPrivateKey
alloc
only.impl Eq for RsaPrivateKey
alloc
only.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