[−][src]Struct rsa::RSAPublicKey
Represents the public part of an RSA key.
Implementations
impl RSAPublicKey
[src]
pub fn new(n: BigUint, e: BigUint) -> Result<Self>
[src]
Create a new key from its components.
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]
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]
fn clone(&self) -> RSAPublicKey
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for RSAPublicKey
[src]
impl Eq for RSAPublicKey
[src]
impl<'_> From<&'_ RSAPrivateKey> for RSAPublicKey
[src]
fn from(private_key: &RSAPrivateKey) -> Self
[src]
impl From<RSAPrivateKey> for RSAPublicKey
[src]
fn from(private_key: RSAPrivateKey) -> Self
[src]
impl PartialEq<RSAPublicKey> for RSAPublicKey
[src]
fn eq(&self, other: &RSAPublicKey) -> bool
[src]
fn ne(&self, other: &RSAPublicKey) -> bool
[src]
impl PublicKey for RSAPublicKey
[src]
fn encrypt<R: Rng>(
&self,
rng: &mut R,
padding: PaddingScheme,
msg: &[u8]
) -> Result<Vec<u8>>
[src]
&self,
rng: &mut R,
padding: PaddingScheme,
msg: &[u8]
) -> Result<Vec<u8>>
fn verify(
&self,
padding: PaddingScheme,
hashed: &[u8],
sig: &[u8]
) -> Result<()>
[src]
&self,
padding: PaddingScheme,
hashed: &[u8],
sig: &[u8]
) -> Result<()>
impl<'a> PublicKey for &'a RSAPublicKey
[src]
fn encrypt<R: Rng>(
&self,
rng: &mut R,
padding: PaddingScheme,
msg: &[u8]
) -> Result<Vec<u8>>
[src]
&self,
rng: &mut R,
padding: PaddingScheme,
msg: &[u8]
) -> Result<Vec<u8>>
fn verify(
&self,
padding: PaddingScheme,
hashed: &[u8],
sig: &[u8]
) -> Result<()>
[src]
&self,
padding: PaddingScheme,
hashed: &[u8],
sig: &[u8]
) -> Result<()>
impl PublicKeyParts for RSAPublicKey
[src]
impl<'a> PublicKeyParts for &'a RSAPublicKey
[src]
fn n(&self) -> &BigUint
[src]
Returns the modulus of the key.
fn e(&self) -> &BigUint
[src]
Returns the public exponent of the key.
fn size(&self) -> usize
[src]
impl StructuralEq for RSAPublicKey
[src]
impl StructuralPartialEq for RSAPublicKey
[src]
impl TryFrom<Pem> for RSAPublicKey
[src]
type Error = Error
The type returned in the event of a conversion error.
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");
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,