Skip to main content

EncryptionEngine

Struct EncryptionEngine 

Source
pub struct EncryptionEngine { /* private fields */ }
Expand description

加密引擎

Implementations§

Source§

impl EncryptionEngine

Source

pub fn new() -> Self

创建新的加密引擎

Source

pub fn with_config(config: EncryptionConfig) -> Self

使用配置创建

Source

pub fn generate_key(&self) -> Result<String, EncryptionError>

生成并添加新密钥

Source

pub fn generate_key_with_algorithm( &self, algorithm: EncryptionAlgorithm, ) -> Result<String, EncryptionError>

使用指定算法生成密钥

Source

pub fn derive_key_from_password( &self, password: &str, salt: &[u8], ) -> Result<String, EncryptionError>

从密码派生并添加密钥

Source

pub fn add_key(&self, key: EncryptionKey) -> Result<String, EncryptionError>

添加已有密钥

Source

pub fn get_key(&self, key_id: &str) -> Result<EncryptionKey, EncryptionError>

获取密钥

Source

pub fn remove_key(&self, key_id: &str) -> Result<bool, EncryptionError>

删除密钥

Source

pub fn list_keys(&self) -> Vec<String>

列出所有密钥 ID

Source

pub fn get_default_key(&self) -> Result<EncryptionKey, EncryptionError>

获取默认密钥

Source

pub fn set_default_key(&self, key_id: &str) -> Result<(), EncryptionError>

设置默认密钥

Source

pub fn encrypt( &self, plaintext: &[u8], ) -> Result<EncryptedData, EncryptionError>

加密数据

Source

pub fn encrypt_with_key( &self, key: &EncryptionKey, plaintext: &[u8], ) -> Result<EncryptedData, EncryptionError>

使用指定密钥加密

Source

pub fn encrypt_string( &self, plaintext: &str, ) -> Result<EncryptedData, EncryptionError>

加密字符串

Source

pub fn decrypt( &self, encrypted: &EncryptedData, ) -> Result<Vec<u8>, EncryptionError>

解密数据

Source

pub fn decrypt_with_key( &self, key: &EncryptionKey, encrypted: &EncryptedData, ) -> Result<Vec<u8>, EncryptionError>

使用指定密钥解密

Source

pub fn decrypt_to_string( &self, encrypted: &EncryptedData, ) -> Result<String, EncryptionError>

解密为字符串

Source

pub fn rotate_key(&self, old_key_id: &str) -> Result<String, EncryptionError>

轮换密钥

Source

pub fn get_keys_requiring_rotation(&self) -> Vec<String>

获取需要轮换的密钥

Source

pub fn export_key(&self, key_id: &str) -> Result<String, EncryptionError>

导出密钥(Base64)

Source

pub fn import_key( &self, key_b64: &str, algorithm: EncryptionAlgorithm, ) -> Result<String, EncryptionError>

导入密钥(Base64)

Source

pub fn key_count(&self) -> usize

密钥数量

Source

pub fn has_default_key(&self) -> bool

是否有默认密钥

Trait Implementations§

Source§

impl Default for EncryptionEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<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