Crates.io | rskit |
lib.rs | rskit |
version | 0.0.30 |
source | src |
created_at | 2024-04-30 02:12:23.978396 |
updated_at | 2024-11-06 06:20:15.039689 |
description | rust kit |
homepage | |
repository | https://github.com/itooling/rskit |
max_upload_size | |
id | 1224623 |
size | 33,775 |
You can use cache to store data and support multi-threaded sharing.
let cache = rskit::cache::Cache::new();
cache.set("name", "iclings");
let name = cache.get::<&str>("name").unwrap();
println!("name is {}", name);
let s = "hello world";
let res = atob(s.as_bytes()).unwrap();
println!("res is: {}", res);
let s = "hello world";
let ss = atob(s.as_bytes()).unwrap();
let res = btoa(&ss).unwrap();
println!("res is: {}", String::from_utf8(res).unwrap());
use std::{thread, time::Duration};
rskit::Log::new().init_file().unwrap();
rskit::log::info!("init log ...");
thread::sleep(Duration::from_secs(1));
let mut config = rskit::Configs::<Settings>::new();
let settings = config.init(None).unwrap();
println!("version: {}", settings.app.version);
use rskit::sd::*;
let aoo = Aoo {
name: String::from("ok"),
age: 18,
date: Local::now(),
};
match to_json(aoo) {
Ok(s) => {
println!("aoo is {}", s);
}
Err(e) => println!("to_json error: {}", e),
}
use rskit::sd::*;
let s = r#"{"name":"ok","age":18, "date": "2024-08-15 11:00:16.100"}"#;
match from_json::<'_, Aoo>(s) {
Ok(aoo) => {
println!("aoo is: {:?}", aoo);
}
Err(e) => println!("from_json error: {}", e),
}
use rskit::str::*;
let res = hash_256("hello world");
println!("hash 256 is {}", res);
use rskit::str::*;
let res = hash_512("hello world");
println!("hash 512 is {}", res);
use rskit::crypto::*;
gen_rand_string(None);
use rskit::crypto::*;
let key = gen_rand_string(Some(16));
let key = key.as_bytes();
let des = encrypt_aes_cbc_128(key, b"hello world");
let res = decrypt_aes_cbc_128(key, des.as_slice());
println!(
"aes cbc 128 decrypt is {:?}",
String::from_utf8(res).unwrap()
);
use rskit::crypto::*;
let key = gen_rand_string(Some(32));
let key = key.as_bytes();
let des = encrypt_aes_cbc_256(key, b"hello world");
let res = decrypt_aes_cbc_256(key, des.as_slice());
println!(
"aes cbc 256 decrypt is {:?}",
String::from_utf8(res).unwrap()
);
use rskit::crypto::*;
let key = aes_gcm_key_128();
let nonce = aes_gcm_nonce_128();
let des = encrypt_aes_gcm_128(&key, &nonce, b"hello world");
let res = decrypt_aes_gcm_128(&key, &nonce, des.as_slice());
println!(
"aes gcm 128 decrypt is {:?}",
String::from_utf8(res).unwrap()
);
use rskit::crypto::*;
let key = aes_gcm_key_256();
let nonce = aes_gcm_nonce_256();
let des = encrypt_aes_gcm_256(&key, &nonce, b"hello world");
let res = decrypt_aes_gcm_256(&key, &nonce, des.as_slice());
println!(
"aes gcm 256 decrypt is {:?}",
String::from_utf8(res).unwrap()
);
use rskit::crypto::*;
let res = generate_rsa_pair(None);
println!("key pair: {:?}", res);
use rskit::crypto::*;
let (pri_key, pub_key) = generate_rsa_pair(None);
let src = "hello world";
let enc = encrypt_rsa_base(&pub_key, src.as_bytes()).unwrap();
let res = decrypt_rsa_base(&pri_key, &enc).unwrap();
println!("src: {}", src);
println!("res: {}", String::from_utf8(res).unwrap());