Struct rsa::RsaPublicKey
source · pub struct RsaPublicKey { /* private fields */ }
Expand description
Represents the public part of an RSA key.
Implementations§
source§impl RsaPublicKey
impl RsaPublicKey
sourcepub fn encrypt<R: CryptoRngCore, P: PaddingScheme>(
&self,
rng: &mut R,
padding: P,
msg: &[u8]
) -> Result<Vec<u8>>
pub fn encrypt<R: CryptoRngCore, P: PaddingScheme>( &self, rng: &mut R, padding: P, msg: &[u8] ) -> Result<Vec<u8>>
Encrypt the given message.
sourcepub fn verify<S: SignatureScheme>(
&self,
scheme: S,
hashed: &[u8],
sig: &[u8]
) -> Result<()>
pub fn verify<S: SignatureScheme>( &self, scheme: S, hashed: &[u8], sig: &[u8] ) -> Result<()>
Verify a signed message.
hashed
must be the result of hashing the input using the hashing function
passed in through hash
.
If the message is valid Ok(())
is returned, otherwise an Err
indicating failure.
source§impl RsaPublicKey
impl RsaPublicKey
sourcepub const MIN_PUB_EXPONENT: u64 = 2u64
pub const MIN_PUB_EXPONENT: u64 = 2u64
Minimum value of the public exponent e
.
sourcepub const MAX_PUB_EXPONENT: u64 = 8_589_934_591u64
pub const MAX_PUB_EXPONENT: u64 = 8_589_934_591u64
Maximum value of the public exponent e
.
sourcepub fn new(n: BigUint, e: BigUint) -> Result<Self>
pub fn new(n: BigUint, e: BigUint) -> Result<Self>
Create a new public key from its components.
This function accepts public keys with a modulus size up to 4096-bits,
i.e. RsaPublicKey::MAX_SIZE
.
sourcepub fn new_with_max_size(
n: BigUint,
e: BigUint,
max_size: usize
) -> Result<Self>
pub fn new_with_max_size( n: BigUint, e: BigUint, max_size: usize ) -> Result<Self>
Create a new public key from its components.
sourcepub fn new_unchecked(n: BigUint, e: BigUint) -> Self
pub fn new_unchecked(n: BigUint, e: BigUint) -> Self
Create a new public key, bypassing checks around the modulus and public exponent size.
This method is not recommended, and only intended for unusual use cases.
Most applications should use RsaPublicKey::new
or
RsaPublicKey::new_with_max_size
instead.
Trait Implementations§
source§impl AsRef<RsaPublicKey> for RsaPrivateKey
impl AsRef<RsaPublicKey> for RsaPrivateKey
source§fn as_ref(&self) -> &RsaPublicKey
fn as_ref(&self) -> &RsaPublicKey
source§impl<D> AsRef<RsaPublicKey> for VerifyingKey<D>where
D: Digest,
impl<D> AsRef<RsaPublicKey> for VerifyingKey<D>where D: Digest,
source§fn as_ref(&self) -> &RsaPublicKey
fn as_ref(&self) -> &RsaPublicKey
source§impl<D> AsRef<RsaPublicKey> for VerifyingKey<D>where
D: Digest,
impl<D> AsRef<RsaPublicKey> for VerifyingKey<D>where D: Digest,
source§fn as_ref(&self) -> &RsaPublicKey
fn as_ref(&self) -> &RsaPublicKey
source§impl Clone for RsaPublicKey
impl Clone for RsaPublicKey
source§fn clone(&self) -> RsaPublicKey
fn clone(&self) -> RsaPublicKey
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RsaPublicKey
impl Debug for RsaPublicKey
source§impl<'de> Deserialize<'de> for RsaPublicKey
impl<'de> Deserialize<'de> for RsaPublicKey
source§fn 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>,
source§impl EncodePublicKey for RsaPublicKey
impl EncodePublicKey for RsaPublicKey
source§fn to_public_key_der(&self) -> Result<Document>
fn to_public_key_der(&self) -> Result<Document>
Document
] containing a SPKI-encoded public key.source§fn to_public_key_pem(&self, line_ending: LineEnding) -> Result<String, Error>
fn to_public_key_pem(&self, line_ending: LineEnding) -> Result<String, Error>
pem
only.LineEnding
].source§impl From<&RsaPrivateKey> for RsaPublicKey
impl From<&RsaPrivateKey> for RsaPublicKey
source§fn from(private_key: &RsaPrivateKey) -> Self
fn from(private_key: &RsaPrivateKey) -> Self
source§impl From<RsaPrivateKey> for RsaPublicKey
impl From<RsaPrivateKey> for RsaPublicKey
source§fn from(private_key: RsaPrivateKey) -> Self
fn from(private_key: RsaPrivateKey) -> Self
source§impl<D> From<RsaPublicKey> for VerifyingKey<D>where
D: Digest,
impl<D> From<RsaPublicKey> for VerifyingKey<D>where D: Digest,
source§fn from(key: RsaPublicKey) -> Self
fn from(key: RsaPublicKey) -> Self
source§impl<D> From<RsaPublicKey> for VerifyingKey<D>where
D: Digest,
impl<D> From<RsaPublicKey> for VerifyingKey<D>where D: Digest,
source§fn from(key: RsaPublicKey) -> Self
fn from(key: RsaPublicKey) -> Self
source§impl<D> From<VerifyingKey<D>> for RsaPublicKeywhere
D: Digest,
impl<D> From<VerifyingKey<D>> for RsaPublicKeywhere D: Digest,
source§fn from(key: VerifyingKey<D>) -> Self
fn from(key: VerifyingKey<D>) -> Self
source§impl<D> From<VerifyingKey<D>> for RsaPublicKeywhere
D: Digest,
impl<D> From<VerifyingKey<D>> for RsaPublicKeywhere D: Digest,
source§fn from(key: VerifyingKey<D>) -> Self
fn from(key: VerifyingKey<D>) -> Self
source§impl Hash for RsaPublicKey
impl Hash for RsaPublicKey
source§impl PartialEq for RsaPublicKey
impl PartialEq for RsaPublicKey
source§fn eq(&self, other: &RsaPublicKey) -> bool
fn eq(&self, other: &RsaPublicKey) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PublicKeyParts for RsaPublicKey
impl PublicKeyParts for RsaPublicKey
source§impl Serialize for RsaPublicKey
impl Serialize for RsaPublicKey
source§impl TryFrom<SubjectPublicKeyInfo<AnyRef<'_>, BitStringRef<'_>>> for RsaPublicKey
impl TryFrom<SubjectPublicKeyInfo<AnyRef<'_>, BitStringRef<'_>>> for RsaPublicKey
impl Eq for RsaPublicKey
impl StructuralEq for RsaPublicKey
impl StructuralPartialEq for RsaPublicKey
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> DecodePublicKey for Twhere
T: for<'a> TryFrom<SubjectPublicKeyInfo<AnyRef<'a>, BitStringRef<'a>>, Error = Error>,
impl<T> DecodePublicKey for Twhere T: for<'a> TryFrom<SubjectPublicKeyInfo<AnyRef<'a>, BitStringRef<'a>>, Error = Error>,
source§fn from_public_key_der(bytes: &[u8]) -> Result<T, Error>
fn from_public_key_der(bytes: &[u8]) -> Result<T, Error>
SubjectPublicKeyInfo
]
(binary format).source§fn from_public_key_pem(s: &str) -> Result<Self, Error>
fn from_public_key_pem(s: &str) -> Result<Self, Error>
pem
only.SubjectPublicKeyInfo
]. Read moresource§impl<T> DecodeRsaPublicKey for Twhere
T: for<'a> TryFrom<SubjectPublicKeyInfo<AnyRef<'a>, BitStringRef<'a>>, Error = Error>,
impl<T> DecodeRsaPublicKey for Twhere T: for<'a> TryFrom<SubjectPublicKeyInfo<AnyRef<'a>, BitStringRef<'a>>, Error = Error>,
source§fn from_pkcs1_der(public_key: &[u8]) -> Result<T, Error>
fn from_pkcs1_der(public_key: &[u8]) -> Result<T, Error>
RsaPublicKey
(binary format).source§fn from_pkcs1_pem(s: &str) -> Result<Self, Error>
fn from_pkcs1_pem(s: &str) -> Result<Self, Error>
pem
only.RsaPublicKey
. Read moresource§fn read_pkcs1_der_file(path: impl AsRef<Path>) -> Result<Self, Error>
fn read_pkcs1_der_file(path: impl AsRef<Path>) -> Result<Self, Error>
std
only.RsaPublicKey
from an ASN.1 DER-encoded file on the local
filesystem (binary format).source§fn read_pkcs1_pem_file(path: impl AsRef<Path>) -> Result<Self, Error>
fn read_pkcs1_pem_file(path: impl AsRef<Path>) -> Result<Self, Error>
pem
and std
only.RsaPublicKey
from a PEM-encoded file on the local filesystem.source§impl<T> EncodeRsaPublicKey for Twhere
T: EncodePublicKey,
impl<T> EncodeRsaPublicKey for Twhere T: EncodePublicKey,
source§fn to_pkcs1_der(&self) -> Result<Document, Error>
fn to_pkcs1_der(&self) -> Result<Document, Error>
Document
] containing a PKCS#1-encoded public key.source§fn to_pkcs1_pem(&self, line_ending: LineEnding) -> Result<String, Error>
fn to_pkcs1_pem(&self, line_ending: LineEnding) -> Result<String, Error>
pem
only.