pub fn encrypt(public_key: &str, data: &[u8]) -> Result<Vec<u8>, Box<dyn Error>>Expand description
Encrypts data using a hybrid RSA + AES-GCM approach.
Takes a PEM-encoded RSA public key and plaintext data, then:
- Generates a random AES-256 key
- Encrypts the data with the AES key
- Encrypts the AES key with the RSA public key
- Returns a serialized structure containing everything needed for decryption
§Arguments
public_key- A PEM-encoded RSA public keydata- The plaintext data to encrypt
§Returns
A serialized EncryptedMessage containing the encrypted data
§Errors
Returns an error if:
- The public key is invalid or cannot be parsed
- The encryption process fails
- Serialization fails