feat(crypt):完成DES便捷加密函数。
This commit is contained in:
25
tests/des_cryption.rs
Normal file
25
tests/des_cryption.rs
Normal 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."
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user