Struct aws_lc_rs::signature::RsaKeyPair
source · pub struct RsaKeyPair { /* private fields */ }Expand description
An RSA key pair, used for signing.
Implementations§
source§impl RsaKeyPair
impl RsaKeyPair
sourcepub fn from_pkcs8(pkcs8: &[u8]) -> Result<Self, KeyRejected>
pub fn from_pkcs8(pkcs8: &[u8]) -> Result<Self, KeyRejected>
Parses an unencrypted PKCS#8-encoded RSA private key.
Only two-prime (not multi-prime) keys are supported. The public modulus (n) must be at least 2047 bits. The public modulus must be no larger than 4096 bits. It is recommended that the public modulus be exactly 2048 or 3072 bits. The public exponent must be at least 65537.
The following will generate a 2048-bit RSA private key of the correct form using OpenSSL’s command line tool:
openssl genpkey -algorithm RSA \
-pkeyopt rsa_keygen_bits:2048 \
-pkeyopt rsa_keygen_pubexp:65537 | \
openssl pkcs8 -topk8 -nocrypt -outform der > rsa-2048-private-key.pk8
The following will generate a 3072-bit RSA private key of the correct form:
openssl genpkey -algorithm RSA \
-pkeyopt rsa_keygen_bits:3072 \
-pkeyopt rsa_keygen_pubexp:65537 | \
openssl pkcs8 -topk8 -nocrypt -outform der > rsa-3072-private-key.pk8
Often, keys generated for use in OpenSSL-based software are stored in the Base64 “PEM” format without the PKCS#8 wrapper. Such keys can be converted to binary PKCS#8 form using the OpenSSL command line tool like this:
openssl pkcs8 -topk8 -nocrypt -outform der \
-in rsa-2048-private-key.pem > rsa-2048-private-key.pk8
Base64 (“PEM”) PKCS#8-encoded keys can be converted to the binary PKCS#8 form like this:
openssl pkcs8 -nocrypt -outform der \
-in rsa-2048-private-key.pem > rsa-2048-private-key.pk8
Errors
error::KeyRejected if bytes do not encode an RSA private key or if the key is otherwise
not acceptable.
source§impl RsaKeyPair
impl RsaKeyPair
sourcepub fn sign(
&self,
padding_alg: &'static dyn RsaEncoding,
_rng: &dyn SecureRandom,
msg: &[u8],
signature: &mut [u8]
) -> Result<(), Unspecified>
pub fn sign( &self, padding_alg: &'static dyn RsaEncoding, _rng: &dyn SecureRandom, msg: &[u8], signature: &mut [u8] ) -> Result<(), Unspecified>
Sign msg. msg is digested using the digest algorithm from
padding_alg and the digest is then padded using the padding algorithm
from padding_alg. The signature it written into signature;
signature’s length must be exactly the length returned by
public_modulus_len().
Many other crypto libraries have signing functions that takes a
precomputed digest as input, instead of the message to digest. This
function does not take a precomputed digest; instead, sign
calculates the digest itself.
ring Compatibility
Our implementation ignored the SecureRandom parameter.
Errors
error::Unspecified on error.
With “fips” feature enabled, errors if digest length is greater than u32::MAX.
sourcepub fn public_modulus_len(&self) -> usize
pub fn public_modulus_len(&self) -> usize
Returns the length in bytes of the key pair’s public modulus.
A signature has the same length as the public modulus.