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>
pub fn new<R: Rng>(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: Rng>(
rng: &mut R,
bit_size: usize,
exp: &BigUint
) -> Result<RsaPrivateKey>
pub fn new_with_exp<R: Rng>(
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 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: Rng>(
&self,
rng: &mut R,
padding: PaddingScheme,
ciphertext: &[u8]
) -> Result<Vec<u8>>
pub fn decrypt_blinded<R: Rng>(
&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 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 Drop for RsaPrivateKey
impl Drop for RsaPrivateKey
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 FromRsaPrivateKey for RsaPrivateKey
impl FromRsaPrivateKey for RsaPrivateKey
sourcefn from_pkcs1_private_key(pkcs1_key: RsaPrivateKey<'_>) -> Result<Self>
fn from_pkcs1_private_key(pkcs1_key: RsaPrivateKey<'_>) -> Result<Self>
Parse the RsaPrivateKey
from a PKCS#1-encoded document.
sourcefn from_pkcs1_der(bytes: &[u8]) -> Result<Self, Error>
fn from_pkcs1_der(bytes: &[u8]) -> Result<Self, 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
sourcefn read_pkcs1_der_file(path: &Path) -> Result<Self, Error>
fn read_pkcs1_der_file(path: &Path) -> Result<Self, Error>
Load PKCS#1 private key from an ASN.1 DER-encoded file on the local filesystem (binary format). Read more
sourcefn read_pkcs1_pem_file(path: &Path) -> Result<Self, Error>
fn read_pkcs1_pem_file(path: &Path) -> Result<Self, Error>
Load PKCS#1 private key from a PEM-encoded file on the local filesystem.
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 ToRsaPrivateKey for RsaPrivateKey
impl ToRsaPrivateKey for RsaPrivateKey
sourcefn to_pkcs1_der(&self) -> Result<RsaPrivateKeyDocument>
fn to_pkcs1_der(&self) -> Result<RsaPrivateKeyDocument>
Serialize a RsaPrivateKeyDocument
containing a PKCS#1-encoded private key.
sourcefn to_pkcs1_pem(&self) -> Result<Zeroizing<String>, Error>
fn to_pkcs1_pem(&self) -> Result<Zeroizing<String>, Error>
Serialize this private key as PEM-encoded PKCS#1.
sourcefn to_pkcs1_pem_with_le(
&self,
line_ending: LineEnding
) -> Result<Zeroizing<String>, Error>
fn to_pkcs1_pem_with_le(
&self,
line_ending: LineEnding
) -> Result<Zeroizing<String>, Error>
Serialize this private key as PEM-encoded PKCS#1 with the given LineEnding
.
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<K> FromPrivateKey for K where
K: FromRsaPrivateKey,
impl<K> FromPrivateKey for K where
K: FromRsaPrivateKey,
sourcefn from_pkcs8_private_key_info(
pkcs8_key: PrivateKeyInfo<'_>
) -> Result<K, Error>
fn from_pkcs8_private_key_info(
pkcs8_key: PrivateKeyInfo<'_>
) -> Result<K, Error>
Parse the PrivateKeyInfo
from a PKCS#8-encoded document.
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<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
sourceimpl<K> ToPrivateKey for K where
K: ToRsaPrivateKey,
impl<K> ToPrivateKey for K where
K: ToRsaPrivateKey,
sourcefn to_pkcs8_der(&self) -> Result<PrivateKeyDocument, Error>
fn to_pkcs8_der(&self) -> Result<PrivateKeyDocument, Error>
Serialize a PrivateKeyDocument
containing a PKCS#8-encoded private key.
sourcefn to_pkcs8_pem(&self) -> Result<Zeroizing<String>, Error>
fn to_pkcs8_pem(&self) -> Result<Zeroizing<String>, Error>
Serialize this private key as PEM-encoded PKCS#8.
sourcefn to_pkcs8_pem_with_le(
&self,
line_ending: LineEnding
) -> Result<Zeroizing<String>, Error>
fn to_pkcs8_pem_with_le(
&self,
line_ending: LineEnding
) -> Result<Zeroizing<String>, Error>
Serialize this private key as PEM-encoded PKCS#8 with the given LineEnding
.