decrypt

Function decrypt 

Source
pub fn decrypt(
    private_key: &str,
    data: &[u8],
) -> Result<Vec<u8>, Box<dyn Error>>
Expand description

Decrypts data that was encrypted with the hybrid RSA + AES-GCM approach.

Takes a PEM-encoded RSA private key and encrypted data, then:

  1. Deserializes the encrypted message structure
  2. Decrypts the AES key using the RSA private key
  3. Uses the decrypted AES key to decrypt the actual data

§Arguments

  • private_key - A PEM-encoded RSA private key
  • data - The encrypted data to decrypt (as serialized by encrypt)

§Returns

The decrypted plaintext data

§Errors

Returns an error if:

  • The private key is invalid or cannot be parsed
  • The encrypted data cannot be deserialized
  • The RSA decryption of the AES key fails
  • The AES decryption of the data fails