pub struct SymmetricEncryption { /* private fields */ }Expand description
Symmetric encryption using Fernet (Python cryptography.fernet compatible)
Implementations§
Source§impl SymmetricEncryption
impl SymmetricEncryption
Sourcepub fn new(key: Option<&str>) -> Result<Self>
pub fn new(key: Option<&str>) -> Result<Self>
Create with generated key, or use provided key (base64 URL-safe encoded)
Sourcepub fn generate_key(&mut self) -> Result<String>
pub fn generate_key(&mut self) -> Result<String>
Generate a new key and use it
Sourcepub fn sign(&self, data: &[u8]) -> Result<Vec<u8>>
pub fn sign(&self, data: &[u8]) -> Result<Vec<u8>>
Encrypt data (acts as “sign” in KeyCryptoPrimitive: encrypt-then-verify)
Sourcepub fn verify(&self, data: &[u8], signature: &[u8]) -> Result<bool>
pub fn verify(&self, data: &[u8], signature: &[u8]) -> Result<bool>
Verify by decrypting and comparing to original data
Sourcepub fn encrypt(&self, plaintext: &str) -> Result<String>
pub fn encrypt(&self, plaintext: &str) -> Result<String>
Encrypt plaintext string, return base64 token as string
Trait Implementations§
Source§impl Clone for SymmetricEncryption
impl Clone for SymmetricEncryption
Source§fn clone(&self) -> SymmetricEncryption
fn clone(&self) -> SymmetricEncryption
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SymmetricEncryption
impl RefUnwindSafe for SymmetricEncryption
impl Send for SymmetricEncryption
impl Sync for SymmetricEncryption
impl Unpin for SymmetricEncryption
impl UnsafeUnpin for SymmetricEncryption
impl UnwindSafe for SymmetricEncryption
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