30 releases

new 0.0.30 Nov 6, 2024
0.0.29 Oct 18, 2024
0.0.26 Sep 21, 2024
0.0.18 Aug 23, 2024
0.0.1 Apr 30, 2024

#662 in Cryptography

Download history 15/week @ 2024-07-24 6/week @ 2024-07-31 1466/week @ 2024-08-14 334/week @ 2024-08-21 241/week @ 2024-08-28 30/week @ 2024-09-04 32/week @ 2024-09-11 652/week @ 2024-09-18 99/week @ 2024-09-25 84/week @ 2024-10-02 1/week @ 2024-10-09 478/week @ 2024-10-16 17/week @ 2024-10-23

614 downloads per month

MIT license

33KB
828 lines

rust kit

cache

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);

str

  • string to base64
let s = "hello world";
let res = atob(s.as_bytes()).unwrap();
println!("res is: {}", res);
  • base64 to string
let s = "hello world";
let ss = atob(s.as_bytes()).unwrap();
let res = btoa(&ss).unwrap();
println!("res is: {}", String::from_utf8(res).unwrap());

lib

  • fast_log
use std::{thread, time::Duration};
rskit::Log::new().init_file().unwrap();
rskit::log::info!("init log ...");
thread::sleep(Duration::from_secs(1));
  • config
let mut config = rskit::Configs::<Settings>::new();
let settings = config.init(None).unwrap();
println!("version: {}", settings.app.version);

serde

  • to_json
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),
}
  • from_json
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),
}

hash

  • hash_256
use rskit::str::*;
let res = hash_256("hello world");
println!("hash 256 is {}", res);
  • hash_512
use rskit::str::*;
let res = hash_512("hello world");
println!("hash 512 is {}", res);

crypto

  • generate aes key
use rskit::crypto::*;
gen_rand_string(None);
  • aes cbc 128
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()
);
  • aes cbc 256
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()
);
  • aes gcm 128
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()
);
  • aes gcm 256
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()
);
  • generate rsa pair
use rskit::crypto::*;
let res = generate_rsa_pair(None);
println!("key pair: {:?}", res);
  • rsa
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());

Dependencies

~44–59MB
~1M SLoC