计算密码hash
This commit is contained in:
@@ -29,3 +29,4 @@ mod aes_cbc;
|
|||||||
mod sm4_cbc;
|
mod sm4_cbc;
|
||||||
|
|
||||||
mod xor;
|
mod xor;
|
||||||
|
pub use xor::simple_hash;
|
||||||
|
|||||||
+22
-26
@@ -147,33 +147,29 @@ impl Config {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
#[cfg(any(
|
|
||||||
feature = "aes_gcm",
|
|
||||||
feature = "server_encrypt",
|
|
||||||
feature = "aes_cbc",
|
|
||||||
feature = "aes_ecb",
|
|
||||||
feature = "sm4_cbc"
|
|
||||||
))]
|
|
||||||
pub fn password_hash(&self) -> Option<[u8; 16]> {
|
pub fn password_hash(&self) -> Option<[u8; 16]> {
|
||||||
self.password.as_ref().map(|v| {
|
if let Some(p) = self.password.as_ref() {
|
||||||
use sha2::Digest;
|
match self.cipher_model {
|
||||||
let mut hasher = sha2::Sha256::new();
|
CipherModel::Xor => {
|
||||||
hasher.update(self.cipher_model.to_string().as_bytes());
|
let key = crate::cipher::simple_hash(&format!("Xor{}{}", p, self.token));
|
||||||
hasher.update(v.as_bytes());
|
Some(key[16..].try_into().unwrap())
|
||||||
hasher.update(self.token.as_bytes());
|
}
|
||||||
let key: [u8; 32] = hasher.finalize().into();
|
CipherModel::None => None,
|
||||||
key[16..].try_into().unwrap()
|
#[cfg(cipher)]
|
||||||
})
|
_ => {
|
||||||
}
|
use sha2::Digest;
|
||||||
#[cfg(not(any(
|
let mut hasher = sha2::Sha256::new();
|
||||||
feature = "aes_gcm",
|
hasher.update(self.cipher_model.to_string().as_bytes());
|
||||||
feature = "server_encrypt",
|
hasher.update(p.as_bytes());
|
||||||
feature = "aes_cbc",
|
hasher.update(self.token.as_bytes());
|
||||||
feature = "aes_ecb",
|
let key: [u8; 32] = hasher.finalize().into();
|
||||||
feature = "sm4_cbc"
|
Some(key[16..].try_into().unwrap())
|
||||||
)))]
|
}
|
||||||
pub fn password_hash(&self) -> Option<[u8; 16]> {
|
}
|
||||||
None
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user