pub struct Encryptor;Expand description
Cryptographic utilities for secure data transmission.
This struct provides methods for encrypting sensitive data, particularly environment variables, using industry-standard cryptographic algorithms. It implements the same encryption scheme as the TypeScript client to ensure compatibility with the Phala TEE Cloud platform.
Implementations§
Source§impl Encryptor
impl Encryptor
Sourcepub fn encrypt_env_vars(
env_vars: &[(String, String)],
remote_pubkey_hex: &str,
) -> Result<String, Error>
pub fn encrypt_env_vars( env_vars: &[(String, String)], remote_pubkey_hex: &str, ) -> Result<String, Error>
Encrypts environment variables using X25519 key exchange and AES-GCM.
This method implements a hybrid encryption scheme:
- X25519 for key exchange (establishes a shared secret)
- AES-GCM for authenticated encryption of the actual data
The process is compatible with the TypeScript implementation used by the Phala Cloud API.
§Parameters
env_vars- A slice of key-value pairs representing environment variables to encryptremote_pubkey_hex- The remote public key as a hex string (with or without ‘0x’ prefix)
§Returns
A hex-encoded string containing the ephemeral public key, IV, and encrypted data
§Errors
Returns an error if:
- The public key is not valid hex or has incorrect length
- JSON serialization fails
- Encryption fails
Sourcepub fn encrypt_env_vars_with_fixed_components(
env_vars: &[(String, String)],
remote_pubkey_hex: &str,
ephemeral_pubkey_bytes: [u8; 32],
shared_secret_bytes: [u8; 32],
iv: [u8; 12],
) -> Result<String, Error>
pub fn encrypt_env_vars_with_fixed_components( env_vars: &[(String, String)], remote_pubkey_hex: &str, ephemeral_pubkey_bytes: [u8; 32], shared_secret_bytes: [u8; 32], iv: [u8; 12], ) -> Result<String, Error>
Specialized version that uses a fixed ephemeral public key and IV for compatibility testing or for deterministic results in certain contexts (like tests or migrations).
IMPORTANT: This should NOT be used in production as it eliminates the security benefits of using fresh random values.
§Parameters
env_vars- A slice of key-value pairs representing environment variables to encryptremote_pubkey_hex- The remote public key as a hex string (with or without ‘0x’ prefix)ephemeral_pubkey_bytes- Fixed 32-byte ephemeral public keyiv- Fixed 12-byte initialization vector
§Returns
A hex-encoded string containing the provided ephemeral public key, IV, and encrypted data