pub struct RsaPublicKey { /* private fields */ }Expand description
An RSA public key for JWT verification, supporting both PKCS#1 v1.5 and RSA-PSS signatures.
The algorithm is stored alongside the key because a bare [rsa::PublicKey] cannot tell
whether it must verify RS* (PKCS#1 v1.5) or PS* (RSA-PSS) signatures, nor which hash to use.
§Algorithms
| Variant | JWT Algorithm | Scheme | Hash |
|---|---|---|---|
| RS256 | RS256 | PKCS#1 v1.5 | SHA-256 |
| RS384 | RS384 | PKCS#1 v1.5 | SHA-384 |
| RS512 | RS512 | PKCS#1 v1.5 | SHA-512 |
| PS256 | PS256 | RSA-PSS | SHA-256 |
| PS384 | PS384 | RSA-PSS | SHA-384 |
| PS512 | PS512 | RSA-PSS | SHA-512 |
Signing is not supported — this key type is verification-only.
§Constructors
RsaPublicKey::from_n_e— build from raw modulus and exponent bytes (useful with JWK)RsaPublicKey::from_pkcs1_der— parse from PKCS#1 DERSEQUENCE { INTEGER n, INTEGER e }
§Errors
Returns Error::InvalidKey if the algorithm is not an RSA variant or
if the underlying RSA key parsing fails. Returns Error::InvalidSignature
on verification failures.
Implementations§
Source§impl RsaPublicKey
impl RsaPublicKey
Sourcepub fn from_pkcs1_der(pkcs1_der: &[u8], alg: Algorithm) -> Result<Self, Error>
pub fn from_pkcs1_der(pkcs1_der: &[u8], alg: Algorithm) -> Result<Self, Error>
Parse an RSA public key from PKCS#1 DER bytes.
The input is the raw SEQUENCE { INTEGER n, INTEGER e } inside the
SubjectPublicKeyInfo BIT STRING.
§Errors
Returns Error::InvalidKey if alg is not an RSA algorithm
or if the DER bytes do not encode a valid RSA public key.