pub struct FieldEncryptor { /* private fields */ }Expand description
Field-level encryption using AES-256-GCM.
Each encrypted field has the wire format:
base64(nonce_12_bytes || ciphertext_with_tag)
A fresh random nonce is generated for every encrypt_* call, so
encrypting the same plaintext twice yields different ciphertext.
Implementations§
Source§impl FieldEncryptor
impl FieldEncryptor
Sourcepub fn from_hex_key(hex_key: &str) -> Result<Self, EncryptionError>
pub fn from_hex_key(hex_key: &str) -> Result<Self, EncryptionError>
Create from a hex-encoded key string (64 hex chars = 32 bytes).
Sourcepub fn from_env() -> Result<Option<Self>, EncryptionError>
pub fn from_env() -> Result<Option<Self>, EncryptionError>
Create from the ARBITER_STORAGE_ENCRYPTION_KEY environment variable.
Returns Ok(None) when the variable is absent or empty (encryption
disabled). Returns Err when the variable is present but malformed.
Sourcepub fn encrypt_field(&self, plaintext: &str) -> Result<String, EncryptionError>
pub fn encrypt_field(&self, plaintext: &str) -> Result<String, EncryptionError>
Encrypt a UTF-8 string field.
Returns a base64-encoded blob containing nonce || ciphertext.
Sourcepub fn decrypt_field(&self, encoded: &str) -> Result<String, EncryptionError>
pub fn decrypt_field(&self, encoded: &str) -> Result<String, EncryptionError>
Decrypt a base64-encoded nonce || ciphertext blob back to the
original UTF-8 string.
Sourcepub fn encrypt_string_vec(
&self,
values: &[String],
) -> Result<String, EncryptionError>
pub fn encrypt_string_vec( &self, values: &[String], ) -> Result<String, EncryptionError>
Encrypt a Vec<String> by JSON-serializing then encrypting.
Sourcepub fn decrypt_string_vec(
&self,
ciphertext: &str,
) -> Result<Vec<String>, EncryptionError>
pub fn decrypt_string_vec( &self, ciphertext: &str, ) -> Result<Vec<String>, EncryptionError>
Decrypt back to Vec<String>.
Trait Implementations§
Source§impl Clone for FieldEncryptor
impl Clone for FieldEncryptor
Source§fn clone(&self) -> FieldEncryptor
fn clone(&self) -> FieldEncryptor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more