Struct rsa::RSAPrivateKey [−][src]
pub struct RSAPrivateKey { /* fields omitted */ }
Expand description
Represents a whole RSA key, public and private parts.
Implementations
impl RSAPrivateKey
[src]
impl RSAPrivateKey
[src]pub fn new<R: Rng>(rng: &mut R, bit_size: usize) -> Result<RSAPrivateKey>
[src]
pub fn new<R: Rng>(rng: &mut R, bit_size: usize) -> Result<RSAPrivateKey>
[src]Generate a new RSA key pair of the given bit size using the passed in rng
.
pub fn from_components(
n: BigUint,
e: BigUint,
d: BigUint,
primes: Vec<BigUint>
) -> RSAPrivateKey
[src]
pub fn from_components(
n: BigUint,
e: BigUint,
d: BigUint,
primes: Vec<BigUint>
) -> RSAPrivateKey
[src]Constructs an RSA key pair from the individual components.
pub fn from_pkcs1(der: &[u8]) -> Result<RSAPrivateKey>
[src]
pub fn from_pkcs1(der: &[u8]) -> Result<RSAPrivateKey>
[src]Parse a PKCS1
encoded RSA Private Key.
The der
data is expected to be the base64
decoded content
following a -----BEGIN RSA PRIVATE KEY-----
header.
https://tls.mbed.org/kb/cryptography/asn1-key-structures-in-der-and-pem
Example
use rsa::RSAPrivateKey; let file_content = r#" -----BEGIN RSA PRIVATE KEY----- MIIBOwIBAAJBAK5Z7jk1ql5DquRvlPmFgyBDCvdPQ0T2si2oPAUmNw2Z/qb2Sr/B EBoWpagFf8Gl1K4PRipJSudDl6N/Vdb2CYkCAwEAAQJBAI3vWCfqsE8c9zoQPE8F icHx0jOSq0ixLExO8M2gVqESq3SJpWbEbvPPbRb1sIqZHe5wV3Xmj09zvUzfdeB7 C6ECIQDjoB/kp7QlRiNhgudhQPct8XUf6Cgp7hBxL2K9Q9UzawIhAMQVvtH1TUOd aSWiqrFx7w+54o58fIpkecI5Kl0TaWfbAiBrnye1Kn2IKhNMZWIUn2y+8izYeyGS QZbQjQD4T3wcJQIgKGgWv2teNZ29ai0AIbrJuaLjhdsvStFzqctf6Hg0k1sCIQCj JdwDGF7Kanex70KAacmOlw3vfx6XWT+2PH6Qh8tLug== -----END RSA PRIVATE KEY----- "#; let der_encoded = file_content .lines() .filter(|line| !line.starts_with("-")) .fold(String::new(), |mut data, line| { data.push_str(&line); data }); let der_bytes = base64::decode(&der_encoded).expect("failed to decode base64 content"); let private_key = RSAPrivateKey::from_pkcs1(&der_bytes).expect("failed to parse key");
pub fn from_pkcs8(der: &[u8]) -> Result<RSAPrivateKey>
[src]
pub fn from_pkcs8(der: &[u8]) -> Result<RSAPrivateKey>
[src]Parse a PKCS8
encoded RSA Private Key.
The der
data is expected to be the base64
decoded content
following a -----BEGIN PRIVATE KEY-----
header.
https://tls.mbed.org/kb/cryptography/asn1-key-structures-in-der-and-pem
Example
use rsa::RSAPrivateKey; let file_content = r#" -----BEGIN PRIVATE KEY----- MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEArlnuOTWqXkOq5G+U +YWDIEMK909DRPayLag8BSY3DZn+pvZKv8EQGhalqAV/waXUrg9GKklK50OXo39V 1vYJiQIDAQABAkEAje9YJ+qwTxz3OhA8TwWJwfHSM5KrSLEsTE7wzaBWoRKrdIml ZsRu889tFvWwipkd7nBXdeaPT3O9TN914HsLoQIhAOOgH+SntCVGI2GC52FA9y3x dR/oKCnuEHEvYr1D1TNrAiEAxBW+0fVNQ51pJaKqsXHvD7nijnx8imR5wjkqXRNp Z9sCIGufJ7UqfYgqE0xlYhSfbL7yLNh7IZJBltCNAPhPfBwlAiAoaBa/a141nb1q LQAhusm5ouOF2y9K0XOpy1/oeDSTWwIhAKMl3AMYXspqd7HvQoBpyY6XDe9/HpdZ P7Y8fpCHy0u6 -----END PRIVATE KEY----- "#; let der_encoded = file_content .lines() .filter(|line| !line.starts_with("-")) .fold(String::new(), |mut data, line| { data.push_str(&line); data }); let der_bytes = base64::decode(&der_encoded).expect("failed to decode base64 content"); let private_key = RSAPrivateKey::from_pkcs8(&der_bytes).expect("failed to parse key");
pub fn to_public_key(&self) -> RSAPublicKey
[src]
pub fn to_public_key(&self) -> RSAPublicKey
[src]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.
pub fn precompute(&mut self) -> Result<()>
[src]
pub fn precompute(&mut self) -> Result<()>
[src]Performs some calculations to speed up private key operations.
pub fn validate(&self) -> Result<()>
[src]
pub fn validate(&self) -> Result<()>
[src]Performs basic sanity checks on the key.
Returns Ok(())
if everything is good, otherwise an approriate error.
pub fn decrypt(
&self,
padding: PaddingScheme,
ciphertext: &[u8]
) -> Result<Vec<u8>>
[src]
pub fn decrypt(
&self,
padding: PaddingScheme,
ciphertext: &[u8]
) -> Result<Vec<u8>>
[src]Decrypt the given message.
pub fn decrypt_blinded<R: Rng>(
&self,
rng: &mut R,
padding: PaddingScheme,
ciphertext: &[u8]
) -> Result<Vec<u8>>
[src]
pub fn decrypt_blinded<R: Rng>(
&self,
rng: &mut R,
padding: PaddingScheme,
ciphertext: &[u8]
) -> Result<Vec<u8>>
[src]Decrypt the given message.
Uses rng
to blind the decryption process.
Methods from Deref<Target = RSAPublicKey>
Trait Implementations
impl Clone for RSAPrivateKey
[src]
impl Clone for RSAPrivateKey
[src]fn clone(&self) -> RSAPrivateKey
[src]
fn clone(&self) -> RSAPrivateKey
[src]Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]Performs copy-assignment from source
. Read more
impl Debug for RSAPrivateKey
[src]
impl Debug for RSAPrivateKey
[src]impl Deref for RSAPrivateKey
[src]
impl Deref for RSAPrivateKey
[src]type Target = RSAPublicKey
type Target = RSAPublicKey
The resulting type after dereferencing.
fn deref(&self) -> &RSAPublicKey
[src]
fn deref(&self) -> &RSAPublicKey
[src]Dereferences the value.
impl<'de> Deserialize<'de> for RSAPrivateKey
[src]
impl<'de> Deserialize<'de> for RSAPrivateKey
[src]fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
impl Drop for RSAPrivateKey
[src]
impl Drop for RSAPrivateKey
[src]impl From<&'_ RSAPrivateKey> for RSAPublicKey
[src]
impl From<&'_ RSAPrivateKey> for RSAPublicKey
[src]fn from(private_key: &RSAPrivateKey) -> Self
[src]
fn from(private_key: &RSAPrivateKey) -> Self
[src]Performs the conversion.
impl From<RSAPrivateKey> for RSAPublicKey
[src]
impl From<RSAPrivateKey> for RSAPublicKey
[src]fn from(private_key: RSAPrivateKey) -> Self
[src]
fn from(private_key: RSAPrivateKey) -> Self
[src]Performs the conversion.
impl PartialEq<RSAPrivateKey> for RSAPrivateKey
[src]
impl PartialEq<RSAPrivateKey> for RSAPrivateKey
[src]impl PublicKeyParts for RSAPrivateKey
[src]
impl PublicKeyParts for RSAPrivateKey
[src]impl<'a> PublicKeyParts for &'a RSAPrivateKey
[src]
impl<'a> PublicKeyParts for &'a RSAPrivateKey
[src]impl Serialize for RSAPrivateKey
[src]
impl Serialize for RSAPrivateKey
[src]impl TryFrom<Pem> for RSAPrivateKey
[src]
impl TryFrom<Pem> for RSAPrivateKey
[src]fn try_from(pem: Pem) -> Result<RSAPrivateKey>
[src]
fn try_from(pem: Pem) -> Result<RSAPrivateKey>
[src]Parses a PKCS8
or PKCS1
encoded RSA Private Key.
Expects one of the following pem
headers:
-----BEGIN PRIVATE KEY-----
-----BEGIN RSA PRIVATE KEY-----
Example
use std::convert::TryFrom; use rsa::RSAPrivateKey; let file_content = r#" -----BEGIN RSA PRIVATE KEY----- MIIBOwIBAAJBAK5Z7jk1ql5DquRvlPmFgyBDCvdPQ0T2si2oPAUmNw2Z/qb2Sr/B EBoWpagFf8Gl1K4PRipJSudDl6N/Vdb2CYkCAwEAAQJBAI3vWCfqsE8c9zoQPE8F icHx0jOSq0ixLExO8M2gVqESq3SJpWbEbvPPbRb1sIqZHe5wV3Xmj09zvUzfdeB7 C6ECIQDjoB/kp7QlRiNhgudhQPct8XUf6Cgp7hBxL2K9Q9UzawIhAMQVvtH1TUOd aSWiqrFx7w+54o58fIpkecI5Kl0TaWfbAiBrnye1Kn2IKhNMZWIUn2y+8izYeyGS QZbQjQD4T3wcJQIgKGgWv2teNZ29ai0AIbrJuaLjhdsvStFzqctf6Hg0k1sCIQCj JdwDGF7Kanex70KAacmOlw3vfx6XWT+2PH6Qh8tLug== -----END RSA PRIVATE KEY----- "#; let pem = rsa::pem::parse(file_content).expect("failed to parse pem file"); let private_key = RSAPrivateKey::try_from(pem).expect("failed to parse key");
impl Zeroize for RSAPrivateKey
[src]
impl Zeroize for RSAPrivateKey
[src]impl Eq for RSAPrivateKey
[src]
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
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,