SecureUtil

Struct SecureUtil 

Source
pub struct SecureUtil;
Expand description

加解密工具,摘要算法等也归集次此工具类中

Implementations§

Source§

impl SecureUtil

Source

pub fn aes_random_key() -> String

TODO 待完善

Source

pub fn aes_encode(bytes: &[u8], key: &str) -> String

TODO 待完善

Source

pub fn aes_decode(decode_str: &str, key: &str) -> Vec<u8>

TODO 待完善

Source

pub fn rsa_random_key() -> (String, String)

TODO 待完善

Source

pub fn rsa_encode()

TODO 待完善

Source

pub fn rsa_decode()

TODO 待完善

Source

pub fn sha256_string(bytes: &[u8]) -> String

计算字节数组的SHA256哈希值并返回十六进制字符串

固定生成256 位(32 字节) 的哈希值,以 64 位十六进制字符串形式展示

§参数
  • bytes - 需要计算哈希值的字节数组切片
§返回值

返回SHA256哈希值的十六进制字符串表示

Source

pub fn md5_string(bytes: &[u8]) -> String

Source

pub fn base64_encode(bytes: &[u8]) -> String

对字节数组进行Base64编码

§参数
  • bytes - 需要编码的字节数组切片
§返回值

返回编码后的Base64字符串

Source

pub fn base64_decode(base64_str: &str) -> Result<Vec<u8>, DecodeError>

对Base64编码的字符串进行解码

§参数
  • base64_str - 需要解码的Base64编码字符串
§返回值
  • Ok(Vec<u8>) - 解码成功,返回解码后的字节数据
  • Err(DecodeError) - 解码失败,返回错误信息
§示例
let decoded = base64_decode("SGVsbG8=").unwrap();
assert_eq!(decoded, b"Hello");
Source

pub fn hmac_sha1(data: &[u8], key: &str) -> Vec<u8>

使用HMAC-SHA1算法对数据进行签名

该函数接收待签名的数据和密钥,使用HMAC-SHA1算法生成数字签名。

§参数
  • data - 待签名的字节数据切片
  • key - 用于签名的密钥字符串
§返回值

返回HMAC-SHA1签名结果的字节向量

§Panics

当密钥长度无效时会panic,但在实际中HMAC可以接受任意长度的密钥

Source

pub fn to_md5_str(bytes: &[u8]) -> String

👎Deprecated: This function is deprecated, please use md5_string instead

将字节数组转换为MD5哈希字符串

该函数接收一个字节切片,计算其MD5哈希值,并将结果格式化为十六进制字符串。

§参数
  • bytes - 需要计算MD5哈希的字节数据切片
§返回值

返回表示MD5哈希值的十六进制字符串

§示例
let data = b"hello world";
let md5_str = to_md5_str(data);
assert_eq!(md5_str, "5eb63bbbe01eeed093cb22bb8f5acdc3");
Source

pub fn to_md5(bytes: &[u8]) -> Vec<u8>

计算字节数组的MD5哈希值

§参数
  • bytes - 需要计算MD5哈希值的字节数组切片
§返回值

返回计算得到的MD5哈希值,以字节数组形式表示

§示例
let data = b"hello world";
let hash = to_md5(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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,