Skip to main content

Encryptor

Struct Encryptor 

Source
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

Source

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:

  1. X25519 for key exchange (establishes a shared secret)
  2. 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 encrypt
  • remote_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
Source

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 encrypt
  • remote_pubkey_hex - The remote public key as a hex string (with or without ‘0x’ prefix)
  • ephemeral_pubkey_bytes - Fixed 32-byte ephemeral public key
  • iv - Fixed 12-byte initialization vector
§Returns

A hex-encoded string containing the provided ephemeral public key, IV, and encrypted data

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more