Struct rsa::RSAPublicKey [−][src]
pub struct RSAPublicKey { /* fields omitted */ }Expand description
Represents the public part of an RSA key.
Implementations
impl RSAPublicKey[src]
impl RSAPublicKey[src]pub fn from_pkcs1(der: &[u8]) -> Result<RSAPublicKey>[src]
pub fn from_pkcs1(der: &[u8]) -> Result<RSAPublicKey>[src]Parse a PKCS1 encoded RSA Public Key.
The der data is expected to be the base64 decoded content
following a -----BEGIN RSA PUBLIC KEY----- header.
https://tls.mbed.org/kb/cryptography/asn1-key-structures-in-der-and-pem
Example
use rsa::RSAPublicKey; let file_content = r#" -----BEGIN RSA PUBLIC KEY----- MEgCQQCuWe45NapeQ6rkb5T5hYMgQwr3T0NE9rItqDwFJjcNmf6m9kq/wRAaFqWo BX/BpdSuD0YqSUrnQ5ejf1XW9gmJAgMBAAE= -----END RSA PUBLIC 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 public_key = RSAPublicKey::from_pkcs1(&der_bytes).expect("failed to parse key");
pub fn from_pkcs8(der: &[u8]) -> Result<RSAPublicKey>[src]
pub fn from_pkcs8(der: &[u8]) -> Result<RSAPublicKey>[src]Parse a PKCS8 encoded RSA Public Key.
The der data is expected to be the base64 decoded content
following a -----BEGIN PUBLIC KEY----- header.
https://tls.mbed.org/kb/cryptography/asn1-key-structures-in-der-and-pem
Example
use rsa::RSAPublicKey; let file_content = r#" -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAK5Z7jk1ql5DquRvlPmFgyBDCvdPQ0T2 si2oPAUmNw2Z/qb2Sr/BEBoWpagFf8Gl1K4PRipJSudDl6N/Vdb2CYkCAwEAAQ== -----END PUBLIC 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 public_key = RSAPublicKey::from_pkcs8(&der_bytes).expect("failed to parse key");
Trait Implementations
impl Clone for RSAPublicKey[src]
impl Clone for RSAPublicKey[src]fn clone(&self) -> RSAPublicKey[src]
fn clone(&self) -> RSAPublicKey[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 RSAPublicKey[src]
impl Debug for RSAPublicKey[src]impl<'de> Deserialize<'de> for RSAPublicKey[src]
impl<'de> Deserialize<'de> for RSAPublicKey[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 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<RSAPublicKey> for RSAPublicKey[src]
impl PartialEq<RSAPublicKey> for RSAPublicKey[src]fn eq(&self, other: &RSAPublicKey) -> bool[src]
fn eq(&self, other: &RSAPublicKey) -> bool[src]This method tests for self and other values to be equal, and is used
by ==. Read more
fn ne(&self, other: &RSAPublicKey) -> bool[src]
fn ne(&self, other: &RSAPublicKey) -> bool[src]This method tests for !=.
impl PublicKey for RSAPublicKey[src]
impl PublicKey for RSAPublicKey[src]fn encrypt<R: Rng>(
&self,
rng: &mut R,
padding: PaddingScheme,
msg: &[u8]
) -> Result<Vec<u8>>[src]
fn encrypt<R: Rng>(
&self,
rng: &mut R,
padding: PaddingScheme,
msg: &[u8]
) -> Result<Vec<u8>>[src]Encrypt the given message.
fn verify(
&self,
padding: PaddingScheme,
hashed: &[u8],
sig: &[u8]
) -> Result<()>[src]
fn verify(
&self,
padding: PaddingScheme,
hashed: &[u8],
sig: &[u8]
) -> Result<()>[src]Verify a signed message.
hashedmust be the result of hashing the input using the hashing function
passed in through hash.
If the message is valid Ok(()) is returned, otherwiese an Err indicating failure. Read more
impl<'a> PublicKey for &'a RSAPublicKey[src]
impl<'a> PublicKey for &'a RSAPublicKey[src]fn encrypt<R: Rng>(
&self,
rng: &mut R,
padding: PaddingScheme,
msg: &[u8]
) -> Result<Vec<u8>>[src]
fn encrypt<R: Rng>(
&self,
rng: &mut R,
padding: PaddingScheme,
msg: &[u8]
) -> Result<Vec<u8>>[src]Encrypt the given message.
fn verify(
&self,
padding: PaddingScheme,
hashed: &[u8],
sig: &[u8]
) -> Result<()>[src]
fn verify(
&self,
padding: PaddingScheme,
hashed: &[u8],
sig: &[u8]
) -> Result<()>[src]Verify a signed message.
hashedmust be the result of hashing the input using the hashing function
passed in through hash.
If the message is valid Ok(()) is returned, otherwiese an Err indicating failure. Read more
impl PublicKeyParts for RSAPublicKey[src]
impl PublicKeyParts for RSAPublicKey[src]impl<'a> PublicKeyParts for &'a RSAPublicKey[src]
impl<'a> PublicKeyParts for &'a RSAPublicKey[src]impl Serialize for RSAPublicKey[src]
impl Serialize for RSAPublicKey[src]impl TryFrom<Pem> for RSAPublicKey[src]
impl TryFrom<Pem> for RSAPublicKey[src]fn try_from(pem: Pem) -> Result<RSAPublicKey>[src]
fn try_from(pem: Pem) -> Result<RSAPublicKey>[src]Parses a PKCS8 or PKCS1 encoded RSA Public Key.
Expects one of the following pem headers:
-----BEGIN PUBLIC KEY----------BEGIN RSA PUBLIC KEY-----
Example
use std::convert::TryFrom; use rsa::RSAPublicKey; let file_content = r#" -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAK5Z7jk1ql5DquRvlPmFgyBDCvdPQ0T2 si2oPAUmNw2Z/qb2Sr/BEBoWpagFf8Gl1K4PRipJSudDl6N/Vdb2CYkCAwEAAQ== -----END PUBLIC KEY----- "#; let pem = rsa::pem::parse(file_content).expect("failed to parse pem file"); let public_key = RSAPublicKey::try_from(pem).expect("failed to parse key");
impl Eq for RSAPublicKey[src]
impl StructuralEq for RSAPublicKey[src]
impl StructuralPartialEq for RSAPublicKey[src]
Auto Trait Implementations
impl RefUnwindSafe for RSAPublicKey
impl Send for RSAPublicKey
impl Sync for RSAPublicKey
impl Unpin for RSAPublicKey
impl UnwindSafe for RSAPublicKey
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 = TThe 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>,