feat(crypt):完成DES便捷加密函数。

This commit is contained in:
徐涛
2023-07-02 17:32:49 +08:00
parent 8cbb7f5269
commit 56fef4c3de
4 changed files with 159 additions and 2 deletions

25
tests/des_cryption.rs Normal file
View File

@@ -0,0 +1,25 @@
#[cfg(test)]
mod des_test {
#[test]
fn encrypt_zero_padding() {
let cipher_data =
rs_toolbox::encryption::des::encrypt_zero_padding("123456", "Hello world.");
let cipher_hex = rs_toolbox::serialize::to_hex(cipher_data);
assert_eq!(cipher_hex, "34115b8448d11e6d284576573a28629b");
}
#[test]
fn decrypt_zero_padding() {
let plain_data = rs_toolbox::encryption::des::decrypt_zero_padding(
"123456",
rs_toolbox::serialize::from_hex("34115b8448d11e6d284576573a28629b").unwrap(),
);
if plain_data.is_err() {
panic!("Decrypt failed");
}
assert_eq!(
String::from_utf8(plain_data.unwrap()).unwrap(),
"Hello world."
);
}
}