Skip to main content

RsaPrivateKey

Struct RsaPrivateKey 

Source
pub struct RsaPrivateKey {
    pub n: BigUint,
    pub d: BigUint,
    /* private fields */
}
Expand description

Represents an RSA private key with arbitrary-size modulus and exponent.

Fields§

§n: BigUint§d: BigUint

Implementations§

Source§

impl RsaPrivateKey

Source

pub fn from_be_bytes(n: &[u8], d: &[u8]) -> Result<Self>

Creates private key from big-endian modulus and private exponent bytes.

§Arguments
  • n: RSA modulus encoded as big-endian bytes.
  • d: RSA private exponent encoded as big-endian bytes.
§Returns

Parsed RsaPrivateKey when both fields are non-empty.

§Errors

Returns Error::InvalidLength when fields are empty, or when modulus size is below 2048 bits in default-safe builds (legacy-compatible hazardous mode permits smaller imports), or other RSA component validation errors from [validate_private_components].

Source

pub fn from_u128(n: u128, d: u128) -> Self

Creates private key from small integers for compatibility tests.

§Arguments
  • n: RSA modulus value.
  • d: RSA private exponent value.
§Returns

RsaPrivateKey converted from the provided integer values.

Source

pub fn clear(&mut self)

Clears private key material to a zeroized placeholder state.

§Notes

This mirrors explicit key free/reset lifecycle flows from the C surface.

Source

pub fn with_crt_components( self, p: &[u8], q: &[u8], dp: &[u8], dq: &[u8], qinv: &[u8], ) -> Result<Self>

Attaches RSA CRT decomposition components to this private key.

§Arguments
  • p: First RSA prime factor.
  • q: Second RSA prime factor.
  • dp: d mod (p - 1) CRT exponent.
  • dq: d mod (q - 1) CRT exponent.
  • qinv: q^{-1} mod p CRT coefficient.
§Returns

Updated private key configured with CRT components.

Source

pub fn sign_digest(&self, digest: &[u8]) -> Result<Vec<u8>>

Signs a representative digest interpreted as big-endian integer modulo n.

§Arguments
  • digest: Digest bytes to convert into an RSA message representative.
§Returns

Signature bytes padded to modulus length.

Source

pub fn sign_pkcs1_v15_sha256(&self, msg: &[u8]) -> Result<Vec<u8>>

Signs a message using RSASSA-PKCS1-v1_5 style encoding with SHA-256.

§Arguments
  • msg: Message bytes to hash and sign.
§Returns

PKCS#1 v1.5 RSA signature bytes.

Source

pub fn sign_pkcs1_v15_sha1(&self, msg: &[u8]) -> Result<Vec<u8>>

Signs a message using RSASSA-PKCS1-v1_5 style encoding with SHA-1.

§Arguments
  • msg: Message bytes to hash and sign.
§Returns

PKCS#1 v1.5 RSA signature bytes.

Source

pub fn sign_pkcs1_v15_sha384(&self, msg: &[u8]) -> Result<Vec<u8>>

Signs a message using RSASSA-PKCS1-v1_5 style encoding with SHA-384.

§Arguments
  • msg: Message bytes to hash and sign.
§Returns

PKCS#1 v1.5 RSA signature bytes.

Source

pub fn sign_pkcs1_v15_sha512(&self, msg: &[u8]) -> Result<Vec<u8>>

Signs a message using RSASSA-PKCS1-v1_5 style encoding with SHA-512.

§Arguments
  • msg: Message bytes to hash and sign.
§Returns

PKCS#1 v1.5 RSA signature bytes.

Source

pub fn sign_pss_sha256(&self, msg: &[u8], salt: &[u8]) -> Result<Vec<u8>>

Signs a message using RSASSA-PSS with SHA-256 and caller-provided salt.

§Arguments
  • msg: Message bytes to hash and sign.
  • salt: Caller-provided random salt used by PSS encoding.
§Returns

RSASSA-PSS RSA signature bytes.

Source

pub fn sign_pss_sha384(&self, msg: &[u8], salt: &[u8]) -> Result<Vec<u8>>

Signs a message using RSASSA-PSS with SHA-384 and caller-provided salt.

§Arguments
  • msg: Message bytes to hash and sign.
  • salt: Caller-provided random salt used by PSS encoding.
§Returns

RSASSA-PSS RSA signature bytes.

Source

pub fn decrypt_pkcs1_v15(&self, ciphertext: &[u8]) -> Result<Vec<u8>>

Decrypts RSAES-PKCS1-v1_5 ciphertext with private exponent d.

§Arguments
  • ciphertext: Ciphertext bytes with length equal to modulus length.
§Returns

Decrypted plaintext when PKCS#1 v1.5 structure is valid.

Source

pub fn decrypt_pkcs1_v15_crt_only(&self, ciphertext: &[u8]) -> Result<Vec<u8>>

Decrypts RSAES-PKCS1-v1_5 ciphertext using configured CRT components.

§Arguments
  • ciphertext: Ciphertext bytes with length equal to modulus length.
§Returns

Decrypted plaintext when CRT components are configured and PKCS#1 v1.5 structure is valid.

Source

pub fn decrypt_oaep_sha256( &self, ciphertext: &[u8], label: &[u8], ) -> Result<Vec<u8>>

Decrypts RSAES-OAEP ciphertext with SHA-256 and caller-provided label.

§Arguments
  • ciphertext: Ciphertext bytes with length equal to modulus length.
  • label: OAEP label bytes hashed into encoding parameters.
§Returns

Decrypted plaintext when OAEP structure validates.

Source

pub fn decrypt_oaep_sha256_crt_only( &self, ciphertext: &[u8], label: &[u8], ) -> Result<Vec<u8>>

Decrypts RSAES-OAEP ciphertext using configured CRT components.

§Arguments
  • ciphertext: Ciphertext bytes with length equal to modulus length.
  • label: OAEP label bytes hashed into encoding parameters.
§Returns

Decrypted plaintext when CRT parameters are configured and OAEP structure validates.

Trait Implementations§

Source§

impl Clone for RsaPrivateKey

Source§

fn clone(&self) -> RsaPrivateKey

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RsaPrivateKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for RsaPrivateKey

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.