pub struct Cipher { /* private fields */ }Expand description
A field-level-encryption cipher: AES-256-GCM with HKDF-SHA256-derived keys.
Key material is zeroized on drop.
Implementations§
Source§impl Cipher
impl Cipher
Sourcepub fn new(master_key: &[u8]) -> Result<Self>
pub fn new(master_key: &[u8]) -> Result<Self>
Create a cipher from a master key (must be at least 32 bytes).
Derives an AES key (HKDF info geode-encrypt) and an HMAC key
(HKDF info geode-hmac), both 32 bytes, with an empty salt.
Sourcepub fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>>
pub fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>>
Encrypt plaintext. Output layout: nonce(12) || ciphertext || tag(16).
The 96-bit nonce is drawn from the operating-system CSPRNG via
OsRng, matching the Go driver’s crypto/rand source.
Sourcepub fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>>
pub fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>>
Decrypt a nonce(12) || ciphertext || tag(16) buffer.
Sourcepub fn encrypt_string(&self, plaintext: &str) -> Result<String>
pub fn encrypt_string(&self, plaintext: &str) -> Result<String>
Encrypt a string and return standard padded base64.
Sourcepub fn decrypt_string(&self, encoded: &str) -> Result<String>
pub fn decrypt_string(&self, encoded: &str) -> Result<String>
Decrypt a standard padded base64 string.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Cipher
impl RefUnwindSafe for Cipher
impl Send for Cipher
impl Sync for Cipher
impl Unpin for Cipher
impl UnsafeUnpin for Cipher
impl UnwindSafe for Cipher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request